It does not seem like store can be used in the repl (sveltejs/v2.svelte.dev#213), so I'll explain the issue here.
I am mixing in computed properties into a store. It does not seem like the initial value of newly created store computed properties bubble up to the template.
<p>{{$name}}</p>
<script>
export default {
oncreate() {
this.store.compute('name', ['user'], user => user && user.name)
this.store.set({user: {name: 'Joe'}})
}
}
</script>
To alleviate this issue, I added a compute wrapper:
export function compute(store, name, deps, fn) {
const values__deps = []
for (let i=0; i < deps.length; i++) {
values__deps.push(store.get(deps[i]))
}
const __set = {}
__set[name] = fn(...values__deps)
store.set(__set)
store.compute(name, deps, fn)
return store
}
It does not seem like store can be used in the repl (sveltejs/v2.svelte.dev#213), so I'll explain the issue here.
I am mixing in computed properties into a store. It does not seem like the initial value of newly created store computed properties bubble up to the template.
To alleviate this issue, I added a
computewrapper: