A slightly strange idea: Statically defined watch
and getState
#597
Replies: 3 comments 1 reply
-
This way we could say, just by looking at computational graph and before any actual computations, which parts of the app may have observable side-effects and which are not: If we could statically detect such parts of the app, then it would be possible e.g. to highlight such parts of the app in The DevTools as "unused", which is may be useful for large apps in active development And maybe even some other benefits or performance optimizations: Currently, because But if the effector won't let users to watch stores directly, but e.g. only through special, statically defined units, then this dynamic may become more predictable 🤔 Not sure, if it is a dumb idea or not 🤷♂️ |
Beta Was this translation helpful? Give feedback.
-
I guess, the API could look something like this 🤔 const productsWatcher = createWatcher({
source: $products
})
productsWatcher.getState()
const unwatch = productsWatcher.watch(list => ...)
// e.g. react integration
// view-model.ts
export const modelWatcher = createWatcher({
source: { a: $a, b: $b, c: $c }
})
// ui.tsx
const { a, b, c} = useWatcher(modelWatcher)
// e.g. tests
const eventWatcher = createWatcher({
source: myEvent
})
eventWatcher.watch(jestMockToTrackThisEvent) |
Beta Was this translation helpful? Give feedback.
-
To make this suggestion works, ["effector/babel-plugin", {
"factories": [
{
"path": "testUtils/eventWatcher",
"sideEffects": true
}
]
}] |
Beta Was this translation helpful? Give feedback.
-
Now in the effector you can "look at" any part of the computational graph of the application from any part of it:
This seems to be the only completely dynamic part of the computational graph that remains in the library's api
What about to make it statically defined too? (in the far future, obviously)
Beta Was this translation helpful? Give feedback.
All reactions