-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
runtimeChanges relating to runtime APIsChanges relating to runtime APIs
Description
Describe the problem
Currently the constructor for a writable store takes as a second argument function that is fired when the store gets a first subscriber, the return of this is fired when the store goes from 1 to 0 subscriber.
This function gives you access to the set
function of the store, but in some cases it might be beneficial to actually have access to the update
instead.
This would allow to do something like for example this
const store1 = writable()
const store2 = (() => {
const { subscribe } = writable([], update=> {
return store1.subscribe(value => {
update(current => [...current, value])
})
})
return { subscribe }
})()
Describe the proposed solution
Not 100% sure
- change the signature ? the update function can be used a set as well (breaking change though)
- add a third argument ?
Alternatives considered
Use some kind of construction with a temporary variable
const store1 = writable()
const store2 = (() => {
let arr = []
const { subscribe } = writable(arr, set=> {
return store1.subscribe(value => {
arr = [...arr, value]
set(arr)
})
})
return { subscribe }
})()
Importance
nice to have
Metadata
Metadata
Assignees
Labels
runtimeChanges relating to runtime APIsChanges relating to runtime APIs