mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
Simplify next traffic light functions. (#177)
* Simplify next traffic light functions. * Fix Vue 2
This commit is contained in:
@@ -4,11 +4,7 @@
|
||||
lightIndex: 0,
|
||||
get light() { return this.TRAFFIC_LIGHTS[this.lightIndex] },
|
||||
nextLight() {
|
||||
if (this.lightIndex + 1 > this.TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0
|
||||
} else {
|
||||
this.lightIndex++
|
||||
}
|
||||
this.lightIndex = (this.lightIndex + 1) % this.TRAFFIC_LIGHTS.length;
|
||||
}
|
||||
}"
|
||||
>
|
||||
|
||||
@@ -25,10 +25,6 @@ export class TrafficlightComponent {
|
||||
}
|
||||
|
||||
nextLight() {
|
||||
if (this.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0;
|
||||
} else {
|
||||
this.lightIndex++;
|
||||
}
|
||||
this.lightIndex = (this.lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,7 @@ export class App {
|
||||
light: string = this.TRAFFIC_LIGHTS[this.lightIndex];
|
||||
|
||||
nextLight() {
|
||||
if (this.lightIndex + 1 > this.TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0;
|
||||
} else {
|
||||
this.lightIndex++;
|
||||
}
|
||||
|
||||
this.lightIndex = (this.lightIndex + 1) % this.TRAFFIC_LIGHTS.length;
|
||||
this.light = this.TRAFFIC_LIGHTS[this.lightIndex];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ export class App {
|
||||
}
|
||||
|
||||
nextLight() {
|
||||
if (this.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0;
|
||||
} else {
|
||||
this.lightIndex++;
|
||||
}
|
||||
this.lightIndex = (this.lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,6 @@ export default class TrafficLight extends Component {
|
||||
}
|
||||
|
||||
nextLight = () => {
|
||||
if (this.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0;
|
||||
} else {
|
||||
this.lightIndex++;
|
||||
}
|
||||
this.lightIndex = (this.lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,11 +14,7 @@ export class TrafficLight extends LitElement {
|
||||
}
|
||||
|
||||
nextLight() {
|
||||
if (this.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0;
|
||||
} else {
|
||||
this.lightIndex = this.lightIndex + 1;
|
||||
}
|
||||
this.lightIndex = (this.lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -5,10 +5,7 @@ export default function TrafficLight() {
|
||||
let lightIndex = 0;
|
||||
let currentLight = () => TRAFFIC_LIGHTS[lightIndex];
|
||||
|
||||
const nextLight = () =>
|
||||
lightIndex + 1 > TRAFFIC_LIGHTS.length - 1
|
||||
? (lightIndex = 0)
|
||||
: (lightIndex = lightIndex + 1);
|
||||
const nextLight = () => (lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
|
||||
const instructions = () => {
|
||||
switch (currentLight()) {
|
||||
|
||||
@@ -10,11 +10,7 @@ export const App = component$(() => {
|
||||
const light = TRAFFIC_LIGHTS[store.lightIndex];
|
||||
|
||||
const nextLight = $(() => {
|
||||
if (store.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
store.lightIndex = 0;
|
||||
} else {
|
||||
store.lightIndex += 1;
|
||||
}
|
||||
store.lightIndex = (store.lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -8,11 +8,7 @@ export default function TrafficLight() {
|
||||
const light = TRAFFIC_LIGHTS[lightIndex];
|
||||
|
||||
function nextLight() {
|
||||
if (lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
setLightIndex(0);
|
||||
} else {
|
||||
setLightIndex(lightIndex + 1);
|
||||
}
|
||||
setLightIndex((lightIndex + 1) % TRAFFIC_LIGHTS.length);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -8,11 +8,7 @@ export default function TrafficLight() {
|
||||
const light = () => TRAFFIC_LIGHTS[lightIndex()];
|
||||
|
||||
function nextLight() {
|
||||
if (lightIndex() + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
setLightIndex(0);
|
||||
} else {
|
||||
setLightIndex(lightIndex() + 1);
|
||||
}
|
||||
setLightIndex((lightIndex() + 1) % TRAFFIC_LIGHTS.length);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -5,11 +5,7 @@
|
||||
$: light = TRAFFIC_LIGHTS[lightIndex];
|
||||
|
||||
function nextLight() {
|
||||
if (lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
lightIndex = 0;
|
||||
} else {
|
||||
lightIndex++;
|
||||
}
|
||||
lightIndex = (lightIndex + 1) % TRAFFIC_LIGHTS.length;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,11 +13,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
nextLight() {
|
||||
if (this.lightIndex + 1 > this.TRAFFIC_LIGHTS.length - 1) {
|
||||
this.lightIndex = 0;
|
||||
} else {
|
||||
this.lightIndex++;
|
||||
}
|
||||
this.lightIndex = (this.lightIndex + 1) % this.TRAFFIC_LIGHTS.length;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,11 +6,7 @@ const lightIndex = ref(0);
|
||||
const light = computed(() => TRAFFIC_LIGHTS[lightIndex.value]);
|
||||
|
||||
function nextLight() {
|
||||
if (lightIndex.value + 1 > TRAFFIC_LIGHTS.length - 1) {
|
||||
lightIndex.value = 0;
|
||||
} else {
|
||||
lightIndex.value++;
|
||||
}
|
||||
lightIndex.value = (lightIndex.value + 1) % TRAFFIC_LIGHTS.length;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user