Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This MR brings reactivity out of the box via signals based libraries. You can bring your ogn signals based library or use the `uhtml/preactive` export which already bundles `@preact/signals-core` in it. The main difference with the *reactive* export, or its *preactive* one, is that the *render* function needs the "what to render" second argument to be a callback, otherwise signals don't get a chance to side effect.
- Loading branch information
1 parent
5ef2bb7
commit 99b0330
Showing
15 changed files
with
162 additions
and
92 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
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
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,6 @@ | ||
/*! (c) Andrea Giammarchi - MIT */ | ||
import { Hole, html, svg, htmlFor, svgFor, attr } from './keyed.js'; | ||
|
||
import reactive from './render/reactive.js'; | ||
|
||
export { Hole, reactive, html, svg, htmlFor, svgFor, attr }; |
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 @@ | ||
import { effect } from '@preact/signals-core'; | ||
export * from '@preact/signals-core'; | ||
|
||
import { Hole, reactive, html, svg, htmlFor, svgFor, attr } from '../reactive.js'; | ||
|
||
const render = reactive(effect); | ||
|
||
export { Hole, render, html, svg, htmlFor, svgFor, attr }; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { create, drop } from 'gc-hook'; | ||
|
||
import render from './keyed.js'; | ||
|
||
/** @type {WeakMap<Element | DocumentFragment, Function>} */ | ||
const effects = new WeakMap; | ||
|
||
/** | ||
* @param {Function} dispose | ||
* @returns {void} | ||
*/ | ||
const onGC = dispose => dispose(); | ||
|
||
export default effect => { | ||
/** | ||
* Render with smart updates within a generic container. | ||
* @template T | ||
* @param {T} where the DOM node where to render content | ||
* @param {() => Hole} what the hole to render | ||
* @returns {T} | ||
*/ | ||
return (where, what) => { | ||
let dispose = effects.get(where); | ||
if (dispose) { | ||
drop(dispose); | ||
dispose(); | ||
} | ||
const wr = new WeakRef(where); | ||
dispose = effect(() => { render(wr.deref(), what) }); | ||
effects.set(where, dispose); | ||
return create(dispose, onGC, { return: where }); | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.