-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hook params update in microtask queue
- Loading branch information
Showing
6 changed files
with
72 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { untracked as untrackedOrigin } from 'mobx'; | ||
|
||
interface Untracked { | ||
<T>(action: () => T): T; | ||
func: <T extends any[], R>(fn: (...args: T) => R) => ((...args: T) => R); | ||
} | ||
|
||
export const untracked: Untracked = (action) => { | ||
return untrackedOrigin(action); | ||
} | ||
|
||
untracked.func = (fn) => { | ||
return function handle() { | ||
return untracked(() => fn.apply(this, arguments)); | ||
} | ||
} |
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,27 @@ | ||
import { untracked, signal, autorun } from "../src"; | ||
|
||
it('untracked should work', () => { | ||
const spy = jest.fn(); | ||
|
||
const s = signal(0); | ||
autorun(() => { | ||
spy(untracked(s.get)); | ||
}) | ||
|
||
expect(spy).toBeCalledWith(0); spy.mockClear(); | ||
s(1); | ||
expect(spy).not.toBeCalled(); | ||
}); | ||
|
||
it('untracked func should work', () => { | ||
const spy = jest.fn(); | ||
|
||
const s = signal(0); | ||
autorun(untracked.func(() => { | ||
spy(s.value); | ||
})) | ||
|
||
expect(spy).toBeCalledWith(0); spy.mockClear(); | ||
s(1); | ||
expect(spy).not.toBeCalled(); | ||
}); |