Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak some samples for clarity and better behavior in playgrounds #148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/2-templating/5-dom-ref/alpine/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<input x-init="$el.focus();" />
<input type="checkbox" x-init="$el.indeterminate = true;" />
14 changes: 0 additions & 14 deletions content/2-templating/5-dom-ref/angular/inputfocused.component.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, ViewChild, ElementRef, OnInit } from "@angular/core";

@Component({
selector: "app-inputindeterminate",
template: `<input type="checkbox" #inputRef />`,
})
export class InputindeterminateComponent implements OnInit {
@ViewChild("inputRef", { static: true })
inputRef!: ElementRef<HTMLInputElement>;

ngOnInit() {
this.inputRef.nativeElement.indeterminate = true;
}
}
3 changes: 0 additions & 3 deletions content/2-templating/5-dom-ref/aurelia1/input-focused.html

This file was deleted.

7 changes: 0 additions & 7 deletions content/2-templating/5-dom-ref/aurelia1/input-focused.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<input type="checkbox" ref="inputElement" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class InputIndeterminate {
inputElement: HTMLInputElement;

attached() {
this.inputElement.indeterminate = true;
}
}
1 change: 0 additions & 1 deletion content/2-templating/5-dom-ref/ember/input-focused.hbs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="checkbox" {{this.autofocus}} />
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Component from "@glimmer/component";
import { modifier } from "ember-modifier";

export default class InputFocused extends Component {
autofocus = modifier((element) => element.focus());
export default class InputIndeterminate extends Component {
indeterminate = modifier((element) => element.indeterminate = true);
}

/**
Expand All @@ -13,6 +13,6 @@ export default class InputFocused extends Component {
* - ember-modifier becomes default part of blueprint
* - https://github.com/emberjs/rfcs/pull/757
* - dependencyless support for using
* `autofocus = element => element.focus()`
* `indeterminate = element => element.indeterminate = true`
* instead
*/
16 changes: 0 additions & 16 deletions content/2-templating/5-dom-ref/lit/input-focused.js

This file was deleted.

16 changes: 16 additions & 0 deletions content/2-templating/5-dom-ref/lit/input-indeterminate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LitElement, html } from "lit";
import { customElement } from "lit/decorators.js";
import { ref, createRef } from "lit/directives/ref.js";

@customElement("input-indeterminate")
export class InputIndeterminate extends LitElement {
inputRef = createRef();

firstUpdated() {
this.inputRef.value.indeterminate = true;
}

render() {
return html`<input type="checkbox" ${ref(this.inputRef)} />`;
}
}
9 changes: 0 additions & 9 deletions content/2-templating/5-dom-ref/qwik/InputFocused.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions content/2-templating/5-dom-ref/qwik/InputIndeterminate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { component$, useClientEffect$, useRef } from "@builder.io/qwik";

export const InputIndeterminate = component$(() => {
const inputElement = useRef(null);

useClientEffect$(() => inputElement.current.indeterminate = true);

return <input type="checkbox" ref={inputElement} />;
});
9 changes: 0 additions & 9 deletions content/2-templating/5-dom-ref/react/InputFocused.jsx

This file was deleted.

9 changes: 9 additions & 0 deletions content/2-templating/5-dom-ref/react/InputIndeterminate.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useEffect, useRef } from "react";

export default function InputIndeterminate() {
const inputElement = useRef(null);

useEffect(() => inputElement.current.indeterminate = true, []);

return <input type="checkbox" ref={inputElement} />;
}
9 changes: 0 additions & 9 deletions content/2-templating/5-dom-ref/solid/InputFocused.jsx

This file was deleted.

9 changes: 9 additions & 0 deletions content/2-templating/5-dom-ref/solid/InputIndeterminate.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { onMount } from "solid-js";

export default function InputIndeterminate() {
let inputElement;

onMount(() => inputElement.indeterminate = true);

return <input ref={inputElement} type="checkbox" />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
let inputElement;

onMount(() => {
inputElement.focus();
inputElement.indeterminate = true;
});
</script>

<input bind:this={inputElement} />
<input bind:this={inputElement} type="checkbox" />
11 changes: 0 additions & 11 deletions content/2-templating/5-dom-ref/vue2/InputFocused.vue

This file was deleted.

14 changes: 14 additions & 0 deletions content/2-templating/5-dom-ref/vue2/InputIndeterminate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
export default {
mounted() {
this.$refs.inputElement.indeterminate = true;
},
};
</script>

<template>
<input
ref="inputElement"
type="checkbox"
>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { ref, onMounted } from "vue";
const inputElement = ref();

onMounted(() => {
inputElement.value.focus();
inputElement.value.indeterminate = true;
});
</script>

<template>
<input ref="inputElement">
<input
ref="inputElement"
type="checkbox"
>
</template>
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/alpine/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
lightIndex = (lightIndex + 1) % TRAFFIC_LIGHTS.length
}
}"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 1 addition & 6 deletions content/2-templating/6-conditional/aurelia1/traffic-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/ember/traffic-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/lit/traffic-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/qwik/TrafficLight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/react/TrafficLight.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/solid/TrafficLight.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/vue2/TrafficLight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
},
};
Expand Down
6 changes: 1 addition & 5 deletions content/2-templating/6-conditional/vue3/TrafficLight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
6 changes: 3 additions & 3 deletions content/3-lifecycle/1-on-mount/alpine/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p
x-data="{ pageTitle: '' }"
x-init="$nextTick(() => { pageTitle = document.title })"
x-data="{ viewportSize: '' }"
x-init="$nextTick(() => { viewportSize = `${window.innerWidth} × ${window.innerHeight}` })"
>
Page title: <span x-text="pageTitle"></span>
Viewport size: <span x-text="viewportSize"></span>
</p>
13 changes: 0 additions & 13 deletions content/3-lifecycle/1-on-mount/angular/pagetitle.component.ts

This file was deleted.

Loading