-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from katungi/feat/signals
Feat: Add signals to urban core
- Loading branch information
Showing
10 changed files
with
131 additions
and
43 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,41 @@ | ||
# Signals | ||
|
||
Urban-js now has signals!! :rocket: | ||
|
||
## Introduction | ||
Signals are trending at the moment as the most recommended way to manage global and local state. | ||
❤️ | ||
There are even rumours that signals are being considered as a native JS language feature. | ||
|
||
Our implementation of Signals is built on preact's implementation. To make it work, we use a Babel tranformer to convert our components to reactive components. | ||
|
||
To read more about what problems signals solve, check out [Introduction to Signals in Preact](https://preactjs.com/blog/introducing-signals/) | ||
|
||
## Usage | ||
|
||
Using signals is pretty simple. | ||
|
||
```js | ||
import { useSignal } from "urban-core" | ||
|
||
export default Home() { | ||
const count = useSignal(0); | ||
|
||
<div> | ||
<span className="text-underline mb-8">Signals Demo</span> | ||
<p> | ||
<>Value: {count}</> | ||
</p> | ||
<button onClick={() => count.value++}>Increment</button> | ||
<button onClick={() => count.value--}>Decrement</button> | ||
</div> | ||
} | ||
``` | ||
|
||
Yes, it's that simple. | ||
|
||
We also export more powerful features like compute, useCompute and effect | ||
|
||
Docs on the above are coming soon. | ||
|
||
Meantime, ENJOY SIGNALS! |
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
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { Link } from "react-router-dom"; | ||
import { useSignal } from "../../utils/signals" | ||
|
||
export default function Home() { | ||
const count = useSignal(0); | ||
|
||
return ( | ||
<div> | ||
<h1 style={{color: '#000'}}>Home</h1> | ||
<span className="text-underline">Routing Demo</span> | ||
<h3 style={{ color: '#000' }}>Home</h3> | ||
<Link to={'/about'}>About</Link> | ||
|
||
<div> | ||
<span className="text-underline mb-8">Signals Demo</span> | ||
<p> | ||
<>Value: {count}</> | ||
</p> | ||
<button onClick={() => count.value++}>Increment</button> | ||
<button onClick={() => count.value--}>Decrement</button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
} |
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
File renamed without changes.
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 @@ | ||
export { signal, useSignal, useComputed, computed, effect } from '@preact/signals-react' |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react-swc' | ||
import babel from 'vite-plugin-babel'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
plugins: [react(), babel({ | ||
babelConfig: { | ||
plugins: [["module:@preact/signals-react-transform"]] | ||
} | ||
})], | ||
}) |
Oops, something went wrong.