Could auto subscribe/unsubscribe to a store be implemented? #13
Unanswered
PierBover
asked this question in
Help / Questions
Replies: 1 comment 2 replies
-
Maybe I could implement an internal hook like this? const myStore = new Store({ test: 'abc' })
class Test extends Component {
store = myStore.use()
store2 = myStore.use()
cancelAllStores() {
const hasProp = (obj: any, ...prop: string[]) => {
for (const p of prop) if (!Object.prototype.hasOwnProperty.call(obj, p)) return false
return true
}
Object.keys(this).forEach(k => {
const obj = (this as any)[k]
if (hasProp(obj, 'setState', 'subscribe', 'cancel')) {
console.log('cancel')
obj.cancel()
}
})
}
didUnmount() {
this.cancelAllStores()
}
render() {
return <p>test</p>
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After I saw this example in the docs it made me wonder if this could be automated somehow?
I'm not implying that Nano should provide this feature, but rather if there's any drawback I'm missing that would make this unfeasible.
Beta Was this translation helpful? Give feedback.
All reactions