-
Notifications
You must be signed in to change notification settings - Fork 59
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
Polyfill example effect #212
Comments
Apologies for the confusion. There was a typo in that example. It has been fixed in the repo's readme, just not updated on NPM yet. Here's a link: https://github.com/tc39/proposal-signals/blob/main/packages/signal-polyfill/readme.md @littledan @NullVoxPopuli How do we want to handle releasing polyfill updates? |
Oh needsEnqueue needs to be true at the start, ofc! Here is a typed version of the type CleanUp = () => void;
export function effect(callback: () => void | CleanUp): CleanUp {
let cleanup: void | (() => void);
const computed = new Signal.Computed(() => {
typeof cleanup === 'function' && cleanup();
cleanup = callback();
});
w.watch(computed);
computed.get();
return () => {
w.unwatch(computed);
typeof cleanup === 'function' && cleanup();
};
} |
maybe we should extract to its own Repo so we can have an independently maintained changelog? (I can set up all that automation, etc)
@Phoscur there is an implementation here: https://github.com/proposal-signals/signal-utils/blob/main/src/subtle/microtask-effect.ts And demo'd here: https://jsbin.com/safoqap/edit?html |
A separate repo also has the benefit of separating out issues about the implementation from issues about the specification and design. |
Oh, but that one is different, it leaves out any possibilty to clean up, on purpose? Any reason you don't want (me) to add it? |
how do you mean? it returns a cleanup function that you'd have to call.
I'd be more than happy to receive PRs for alternate effect implementations! |
Comparing https://github.com/proposal-signals/signal-utils/blob/main/src/subtle/microtask-effect.ts and https://github.com/tc39/proposal-signals/blob/main/packages/signal-polyfill/readme.md then the first one (TypeScript) is leaving out the clean-up procedure the callback can provide as a (curried, optional) return: I saw you added the first part (clean-up return for effect) recently, removing some of the extensive comments concerning the memory leakage. So with this we could remove the other comments? The question remains what other pitfalls this "naive" implementation hides? The readme says framework authors are supposed to implement this specifically for batching. So I guess there is some overhead here?
Yeah, it would be really good to see a more advanced scheduler examplewise too. |
I understood this is just a basic (naive) example, but it would be great to see it working anyways!
While I still need to wrap my head around how Signals (and the subtle stuff) work, I'd like to ask you to help me with this:
Let's fix the example from the readme, it's only logging "even" once on Node21:
The text was updated successfully, but these errors were encountered: