parent
5f3b898b42
commit
bc17629a67
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,5 @@ |
||||
<script lang="ts"> |
||||
import HelloWorld from "src/frontends/svelte/HelloWorld.svelte"; |
||||
|
||||
// |
||||
</script> |
||||
|
||||
<HelloWorld /> |
||||
|
@ -1,9 +1,23 @@ |
||||
import React from "react"; |
||||
import { useSignal } from "@gn8/alien-signals-react"; |
||||
|
||||
import { |
||||
deepSignalExample, |
||||
computedSignalFromExample, |
||||
} from "src/ng-mock/js-land/signalLibs/alienSignals"; |
||||
|
||||
export function HelloWorldReact() { |
||||
const [state] = useSignal(deepSignalExample); |
||||
const [computed] = useSignal(computedSignalFromExample); |
||||
|
||||
return ( |
||||
<div> |
||||
<p>Hello World from React!</p> |
||||
<p>Here is a reactive object with {computed.get()} props.</p> |
||||
<pre>{JSON.stringify(state, null, 4)}</pre> |
||||
<button onClick={() => state.array.push(state.array.at(-1) + 1)}> |
||||
Click to add val |
||||
</button> |
||||
</div> |
||||
); |
||||
} |
||||
|
@ -1,7 +1,24 @@ |
||||
<script> |
||||
// Simple Svelte component |
||||
import { useSignal } from "@gn8/alien-signals-svelte"; |
||||
import { |
||||
deepSignalExample, |
||||
computedSignalFromExample, |
||||
} from "src/ng-mock/js-land/signalLibs/alienSignals"; |
||||
|
||||
const nestedObject = useSignal(deepSignalExample); |
||||
const computed = useSignal(computedSignalFromExample); |
||||
</script> |
||||
|
||||
<div> |
||||
<p>Hello World from Svelte!</p> |
||||
|
||||
<p>Here is a reactive object with {$computed.get()} props.</p> |
||||
<pre>{JSON.stringify($nestedObject, null, 4)}</pre> |
||||
<button |
||||
on:click={() => { |
||||
$nestedObject.array.splice(0, 1); |
||||
}} |
||||
> |
||||
Click to remove first array element |
||||
</button> |
||||
</div> |
||||
|
@ -1,22 +0,0 @@ |
||||
// Simple Svelte-like component using vanilla JS
|
||||
export function mountSvelteComponent(element: HTMLElement) { |
||||
// Create the DOM structure that would be created by the Svelte component
|
||||
element.innerHTML = ` |
||||
<div style=" |
||||
padding: 20px;
|
||||
border: 2px solid #000000ff;
|
||||
border-radius: 8px; |
||||
margin: 10px; |
||||
background-color: #fff5f5; |
||||
"> |
||||
<h2>Svelte Component</h2> |
||||
<p>Hello World from Svelte!</p> |
||||
</div> |
||||
`;
|
||||
|
||||
return { |
||||
$destroy: () => { |
||||
element.innerHTML = ""; |
||||
}, |
||||
}; |
||||
} |
@ -1,8 +0,0 @@ |
||||
import { createApp } from "vue"; |
||||
import HelloworldVue from "./HelloWorld.vue"; |
||||
|
||||
export function mountVueComponent(element: HTMLElement) { |
||||
const app = createApp(HelloworldVue); |
||||
app.mount(element); |
||||
return app; |
||||
} |
@ -0,0 +1,45 @@ |
||||
import { deepSignal, watch, computed } from "alien-deepsignals"; |
||||
import { signal } from "alien-signals"; |
||||
|
||||
const deepSignalExample = deepSignal({ |
||||
count: 0, |
||||
name: "John", |
||||
nested: { |
||||
deep: "value", |
||||
}, |
||||
array: [1, 2, 3], |
||||
set: new Set(["el1"]), |
||||
}); |
||||
|
||||
const computedSignalFromExample = computed(() => { |
||||
return Object.keys(deepSignalExample).length; |
||||
}); |
||||
|
||||
/** Create a vanilla alien-signals Signal so that it can be normally used by universe-alien-signals. */ |
||||
const wrapDeepIntoAlienSignal = <T extends object>( |
||||
nestedSignal: ReturnType<typeof deepSignal<T>> |
||||
) => { |
||||
const alienSignal = signal(nestedSignal); |
||||
|
||||
// Watch deep signal and notify vanilla alien-signal on changes.
|
||||
watch( |
||||
nestedSignal, |
||||
(value) => { |
||||
// We need to destructure because the object otherwise remained the same.
|
||||
alienSignal({ ...nestedSignal }); |
||||
}, |
||||
{ deep: true } |
||||
); |
||||
|
||||
return alienSignal; |
||||
}; |
||||
|
||||
const wrappedDeepSignalState = wrapDeepIntoAlienSignal(deepSignalExample); |
||||
const wrappedComputedPropertiesOfObj = wrapDeepIntoAlienSignal( |
||||
computedSignalFromExample |
||||
); |
||||
|
||||
export { |
||||
wrappedDeepSignalState as deepSignalExample, |
||||
wrappedComputedPropertiesOfObj as computedSignalFromExample, |
||||
}; |
Loading…
Reference in new issue