Skip to content

Golf down oldNotify capturing #646

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-chairs-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preact/signals": patch
---

Gold down the oldNotify capturing
18 changes: 11 additions & 7 deletions packages/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ const HAS_PENDING_UPDATE = 1 << 0;
const HAS_HOOK_STATE = 1 << 1;
const HAS_COMPUTEDS = 1 << 2;

let oldNotify: (this: Effect) => void,
effectsQueue: Array<Effect> = [],
domQueue: Array<Effect> = [];

// Capture the original `Effect.prototype._notify` method so that we can install
// custom `._notify`s for each different use-case but still call the original
// implementation in the end. Dispose the temporary effect immediately afterwards.
effect(function (this: Effect) {
oldNotify = this._notify;
})();

// Install a Preact options hook
function hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {
// @ts-ignore-next-line private options hooks usage
Expand Down Expand Up @@ -110,7 +121,6 @@ function SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {
};

effect(function (this: Effect) {
if (!oldNotify) oldNotify = this._notify;
this._notify = notifyDomUpdates;
const val = wrappedSignal.value;
if (isText.value && self.base) {
Expand Down Expand Up @@ -254,7 +264,6 @@ function createPropUpdater(
props = newProps;
},
_dispose: effect(function (this: Effect) {
if (!oldNotify) oldNotify = this._notify;
this._notify = notifyDomUpdates;
const value = changeSignal.value.value;
// If Preact just rendered this value, don't render it again:
Expand Down Expand Up @@ -365,10 +374,6 @@ export function useComputed<T>(compute: () => T) {
return useMemo(() => computed<T>(() => $compute.current()), []);
}

let oldNotify: (this: Effect) => void,
effectsQueue: Array<Effect> = [],
domQueue: Array<Effect> = [];

const deferEffects =
typeof requestAnimationFrame === "undefined"
? setTimeout
Expand Down Expand Up @@ -416,7 +421,6 @@ export function useSignalEffect(cb: () => void | (() => void)) {

useEffect(() => {
return effect(function (this: Effect) {
if (!oldNotify) oldNotify = this._notify;
this._notify = notifyEffects;
return callback.current();
});
Expand Down
Loading