forked from matschik/component-party.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
210 additions
and
1,795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<UserProfile /> |
8 changes: 8 additions & 0 deletions
8
content/4-component-composition/5-context/ember/user-profile.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: {{this.user.username}}</p> | ||
<p>Email: {{this.user.email}}</p> | ||
<button {{on "click" (fn this.userService.updateUserName "Jane")}}> | ||
Update username to Jane | ||
</button> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
content/4-component-composition/5-context/ember/user-profile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Component from '@glimmer/component'; | ||
import { service } from '@ember/service'; | ||
|
||
export default class UserProfileComponent extends Component { | ||
@service userService; | ||
|
||
get user() { | ||
return this.userService.user; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
content/4-component-composition/5-context/ember/user-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Service from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class UserServiceService extends Service { | ||
@tracked id = 1; | ||
@tracked username = 'unicorn42'; | ||
@tracked email = '[email protected]'; | ||
|
||
get user() { | ||
return { | ||
id: this.id, | ||
username: this.username, | ||
email: this.email, | ||
}; | ||
} | ||
|
||
@action | ||
updateUserName(newUsername) { | ||
this.username = newUsername; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
component$, | ||
useStore, | ||
useContextProvider, | ||
createContext, | ||
$, | ||
} from "@builder.io/qwik"; | ||
import UserProfile from "./UserProfile"; | ||
|
||
export const UserContext = createContext("user-context"); | ||
|
||
const App = component$(() => { | ||
const user = useStore({ | ||
id: 1, | ||
username: "unicorn42", | ||
email: "[email protected]", | ||
}); | ||
|
||
const updateUsername = $((newUsername) => { | ||
user.username = newUsername; | ||
}); | ||
|
||
useContextProvider(UserContext, { user, updateUsername }); | ||
|
||
return ( | ||
<> | ||
<h1>Welcome back, {user.username}</h1> | ||
<UserProfile /> | ||
</> | ||
); | ||
}); | ||
|
||
export default App; |
19 changes: 19 additions & 0 deletions
19
content/4-component-composition/5-context/qwik/UserProfile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { component$, useContext } from "@builder.io/qwik"; | ||
import { UserContext } from "./App"; | ||
|
||
const UserProfile = component$(() => { | ||
const { user, updateUsername } = useContext(UserContext); | ||
|
||
return ( | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: {user.username}</p> | ||
<p>Email: {user.email}</p> | ||
<button onClick$={() => updateUsername("Jane")}> | ||
Update username to Jane | ||
</button> | ||
</div> | ||
); | ||
}); | ||
|
||
export default UserProfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script> | ||
import UserProfile from "./UserProfile.vue"; | ||
export default { | ||
components: { UserProfile }, | ||
provide() { | ||
return { | ||
user: Object.assign(this.user, { | ||
updateUsername: this.updateUsername, | ||
}), | ||
}; | ||
}, | ||
data() { | ||
return { | ||
user: { | ||
id: 1, | ||
username: "unicorn42", | ||
email: "[email protected]", | ||
}, | ||
}; | ||
}, | ||
methods: { | ||
updateUsername(newUsername) { | ||
this.user.username = newUsername; | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1>Welcome back, {{ user.username }}</h1> | ||
<UserProfile /> | ||
</div> | ||
</template> |
16 changes: 16 additions & 0 deletions
16
content/4-component-composition/5-context/vue2/UserProfile.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script> | ||
export default { | ||
inject: ["user"], | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: {{ user.username }}</p> | ||
<p>Email: {{ user.email }}</p> | ||
<button @click="() => user.updateUsername('Jane')"> | ||
Update username to Jane | ||
</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script setup> | ||
import { ref, provide } from "vue"; | ||
import UserProfile from "./UserProfile.vue"; | ||
const user = ref({ | ||
id: 1, | ||
username: "unicorn42", | ||
email: "[email protected]", | ||
}); | ||
function updateUsername(username) { | ||
user.value.username = username; | ||
} | ||
provide("user", { user, updateUsername }); | ||
</script> | ||
|
||
<template> | ||
<h1>Welcome back, {{ user.username }}</h1> | ||
<UserProfile /> | ||
</template> |
15 changes: 15 additions & 0 deletions
15
content/4-component-composition/5-context/vue3/UserProfile.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script setup> | ||
import { inject } from "vue"; | ||
const { user, updateUsername } = inject("user"); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: {{ user.username }}</p> | ||
<p>Email: {{ user.email }}</p> | ||
<button @click="() => updateUsername('Jane')"> | ||
Update username to Jane | ||
</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function App() { | ||
return <h1>Hello world</h1>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { render } from "solid-js/web"; | ||
import App from "./App"; | ||
|
||
render(() => <App />, document.getElementById("app")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.