-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
feat(signals-preact): add possibility of deferring effect execution to the next frame #290
Conversation
🦋 Changeset detectedLatest commit: 62fd280 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for preact-signals-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Size Change: +106 B (0%) Total Size: 68.5 kB
ℹ️ View Unchanged
|
Closing due to inactivity |
@JoviDeCroock, we've added this in our codebase and it's working great so far: WordPress/block-interactivity-experiments#226 The only problem is that we had to use the mangled properties instead: // Using the mangled properties:
// this.c: this._callback
// this.x: this._compute
// https://github.com/preactjs/signals/blob/main/mangle.json
function createFlusher(compute, notify) {
let flush;
const dispose = effect(function () {
flush = this.c.bind(this);
this.x = compute;
this.c = notify;
return compute();
});
return { flush, dispose };
} |
I changed the implementation a bit to ignore notifications that happen before the callback has been executed and thus prevent infinite loops: |
Resolve #228
This currently adds support for
useEffect
like execution to theuseSignalEffect
, this is supported by means of a newoptions
second argument, which is an object that allows you to pass in a property namedmode
. By default we will dosync
execution which is the behavior we have seen before, but we also allow for a new type of behavior, namelyafterPaint
which is the same method used asuseEffect
.Currently I did not really see a need to add
useLayoutEffect
but we could in the future, for React we could implement this like the following:Do note that this would only trigger after updating the DOM-node if the relevant property is used on a DOM-node as well
demo