-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
solidjs style computeds & async computeds #188
Comments
It looks interesting. Can somebody make an PR? We need to check the size of this feature. |
I can work on a PR when I have some free time, which will be at least 2 weeks from now. At the very least, this can be a separate package, but it may be small enough to include in this project. To anyone reading this who wants to work on this, don't let this message dissuade you from creating a patch. |
atom: is a function which takes an optional autolisten & returns .get() + .a: active autolisten when atom was instantiated computed: + autolisten: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 259 B
atom: is a function which takes an optional autolisten & returns .get() + .a: active autolisten when atom was instantiated computed: + autolisten: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 259 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: .set: sets computed & does not set undoValue .save: sets computed & sets undoValue .undo: sets computed to undoValue .on: hook which runs callback onMount .off: hook which runs callback onUnmount & before the computed cb being called + async support size-limit: Atom: + 9 B All: + 258 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods deactivated: .off .on .save .set .undo + async support size-limit: Atom: + 9 B All: + 299 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support size-limit: Atom: + 9 B All: + 299 B
atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support size-limit: Atom: + 9 B All: + 295 B
…tosubscribe (nanostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support size-limit: Atom: + 9 B All: + 295 B
For nanostores, I implemented a userland solution here: https://github.com/dtinth/nanostores-computed-dynamic The API looks like this: const $base = atom(0)
const $derived = computedDynamic(use => use($base) + 1)
// `use($store)` is like `$store.get()` but it also tracks the dependency. It is possible to use const $shape = atom('circle')
const $radius = atom(4)
const $width = atom(2)
const $height = atom(3)
const $area = computedDynamic((use) => {
if (use($shape) === 'circle') {
return Math.PI * use($radius) ** 2
}
if (use($shape) === 'rectangle') {
return use($width) * use($height)
}
})
// If $shape changes from 'circle' to 'rectangle', then
// $radius is unsubscribed, and $width and $height are subscribed instead. …or loops (just like React’s const $users = map({
u1: { name: 'John', feeling: '😀' },
u2: { name: 'Mary', feeling: '😀' },
})
const $onlineUserIds = atom(['u1'])
const $userById = (id) => computed($users, (users) => users[id])
const $onlineUsers = computedDynamic((use) => {
const onlineUserIds = use($onlineUserIds)
return onlineUserIds.map((id) => use($userById(id)))
}) Subscriptions are created and destroyed dynamically as the dependencies change across recomputations. It is also possible to use a store to switch between other stores! const $a = atom('a1')
const $b = atom('b1')
const $switcher = atom($a)
const $c = computedDynamic((use) => {
return use(use($switcher))
}) It is not thoroughly tested yet though. I think it’d be great if this is built in to Having the ability to create computed store with dynamic dependencies is important for performance. For example, if you have a |
Hey @dtinth! I created a PR which adds autosubscribe & async support to const $shape = atom('circle')
const $radius = atom(4)
const $width = atom(2)
const $height = atom(3)
const $area = computed(() => {
if ($shape() === 'circle') {
return Math.PI * $radius() ** 2
}
if ($shape() === 'rectangle') {
return $width() * $height()
}
}) const $a = atom('a1')
const $b = atom('b1')
const $switcher = atom($a)
const $c = computed(() => {
return $switcher()()
}) There is also support for async computeds. Re-entrancy is also supported, meaning if a callback is run before a prior callback completes, the prior callback will be marked as "stale". An example: let $personId = atom(0)
computed(async use => {
let person = await fetch(`https://api.com/people/${$personId()}`).then(response => response.json())
if (use.stale()) return // stop run if the cb is stale
let messages = await fetch(`https://api.com/people/${$personId(use)}/messages`).then(response => response.json())
return { person, messages } // This will not be saved if the cb is stale
}) I added tests & have deployed this PR to a medium-sized project & all seems well! @ai, have you had a chance to test the PR? |
@btakita Thanks for the pointer. I took a quick look at the PR.
|
Thank you! There are some additional use cases which includes Event binding & unbinding and Helper functions & Private stores. The helper functions on
First of all, thank you for the type inference tip. I can confirm that it works & now the I can see your point re: keeping the interface small. Another benefit to not having an atom as a function is that the I personally like having I prefer having the api sugar to improve readability of my own projects, but I also would rather not have to document & maintain multiple ways of autosubscribing in the nanostores project...I also have the sense that others, including @TrySound would also prefer the simplicity of only supporting So I appreciate your comments & am adjusting the PR accordingly. If anyone wants to use the |
…tosubscribe (nanostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 9 B All: + 295 B
…tosubscribe (nanostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 9 B All: + 295 B
…tosubscribe (nanostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 9 B All: + 295 B
I removed the I also have the btakita/nanostores#issues/188-atom-fn available which keeps the If we still prefer to have functionless atoms in nanostores, I can extract a new package for the function atoms. Either way, it would be great to have the PR merged. |
Sorry, I still have no time to review that PR. I need to prepare a talk and PR is very big to review it fast. I will try to do it in July. |
…tosubscribe (nanostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: - 4 B All: + 288 B
…tosubscribe (nanostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 9 B All: + 289 B
BREAKING CHANGE: If the `$computed()` returns a `PromiseLike`, the `PromiseLike`'s `.then()` is called to set `$computed.value`. Mitigation: the `$computed()` can return an object wrapping the `PromiseLike`. During the synchronous run of the `computed` callback, the `task` is pushed onto the `taskStack`. Task: + save(newValue: Value): Task<Value> + set(intermediateValue: Value): Task<Value> + stale(): boolean + undo(): Task<Value> size-limit: All: + 78 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 26 B All: + 159 B
BREAKING CHANGE: If the `$computed()` returns a `PromiseLike`, the `PromiseLike`'s `.then()` is called to set `$computed.value`. Mitigation: the `$computed()` can return an object wrapping the `PromiseLike`. During the synchronous run of the `computed` callback, the `task` is pushed onto the `taskStack`. Task: + save(newValue: Value): Task<Value> + set(intermediateValue: Value): Task<Value> + stale(): boolean + undo(): Task<Value> size-limit: All: + 78 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 26 B All: + 159 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 26 B All: + 159 B
BREAKING CHANGE: If the `$computed()` returns a `PromiseLike`, the `PromiseLike`'s `.then()` is called to set `$computed.value`. Mitigation: the `$computed()` can return an object wrapping the `PromiseLike`. During the synchronous run of the `computed` callback, the `task` is pushed onto the `taskStack`. Task: + save(newValue: Value): Task<Value> + set(intermediateValue: Value): Task<Value> + stale(): boolean + undo(): Task<Value> size-limit: All: + 78 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 27 B All: + 157 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 26 B All: + 144 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 26 B All: + 137 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 136 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 132 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 132 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 132 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 131 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 121 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 115 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 115 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 115 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 109 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 109 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 109 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 109 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 106 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 106 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 106 B
+ BoxTask,task,Task,UnboxTask atom: is a function which takes an optional autosubscribe function & returns .get() computed: + task: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 106 B
…tosubscribe (nanostores#188) atom: + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 15 B All: + 300 B
…tosubscribe (nanostores#188) atom: + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .off .on .save .set .undo + async support package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 12 B All: + 297 B
…nostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .onStart .onStop .save .set .undo + async support package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 297 B
…nostores#188) atom: is a function which takes an optional autosubscribe function & returns .get() + .a: active autosubscribe when atom was instantiated computed: + autosubscribe: (): returns computed store's value (store: AnyStore): computed store autosubscribes to the given store (cb: () => any): runs the cb & autosubscribes to any called store functions within the cb .off(cb): hook which runs callback onUnmount & before the computed cb being called .on(cb): hook which runs callback onMount .save(): sets computed & sets undoValue .set(newValue): sets computed & does not set undoValue .stale(): returns true if computed store's cb was called again after call associated with the autosubscribe .undo: sets computed to undoValue a stale autosubscribe has some of it's methods neutered: .onStart .onStop .save .set .undo + async support package.json: description: + SolidJS Thanks to @dtinth for autosubscribe function type inference which he implemented in https://github.com/dtinth/nanostores-computed-dynamic size-limit: Atom: + 25 B All: + 297 B
Solidjs signals use inline dependencies, removing the redundancy of declaring the dependency atoms when the computed is defined. I think we can lazily add dependencies when the computed function is executed.
Perhaps it could look something like:
I think it would work even if a dependency is not reached in a particular execution...
It could also work for async as well. Given that the
get
function argument is necessary to push the caller to the caller stack to track the which computed will be subscribing to the dependency. Solidjs memos are synchronous, so there is no equivalent.or
get
could be used as a sort ofself
argumentThis could also be a separate library which imports nanostores.
The text was updated successfully, but these errors were encountered: