feat(signals-preact): add possibility of deferring effect execution to the next frame#290
Closed
JoviDeCroock wants to merge 3 commits intomainfrom
Closed
feat(signals-preact): add possibility of deferring effect execution to the next frame#290JoviDeCroock wants to merge 3 commits intomainfrom
JoviDeCroock wants to merge 3 commits intomainfrom
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. |
Contributor
|
Size Change: +106 B (0%) Total Size: 68.5 kB
ℹ️ View Unchanged
|
This was referenced Apr 12, 2023
Member
Author
|
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: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve #228
This currently adds support for
useEffectlike execution to theuseSignalEffect, this is supported by means of a newoptionssecond argument, which is an object that allows you to pass in a property namedmode. By default we will dosyncexecution which is the behavior we have seen before, but we also allow for a new type of behavior, namelyafterPaintwhich is the same method used asuseEffect.Currently I did not really see a need to add
useLayoutEffectbut 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