Skip to content

Instantly share code, notes, and snippets.

@dmitry-korolev
Forked from artalar/example.jsx
Last active July 16, 2018 13:58
Show Gist options
  • Save dmitry-korolev/c4d5534a1d55cc8b0c9d42495d6b275e to your computer and use it in GitHub Desktop.
Save dmitry-korolev/c4d5534a1d55cc8b0c9d42495d6b275e to your computer and use it in GitHub Desktop.
[RFC] global stream with declarative suscriptions
/* Example #1 */
// Store.js
// `Atom()` - create new stream
const a = Atom(0);
const b = Atom(0);
// Component.js
// `match()` - create new pattern
// for subscribe and matching updates from store
// when all matches is pass updated data
// from every element of pattern
// will paste in the subscription callback
// For example, we need to subscribes to `a`
// only when it equal `1`
var subscriptionStatic = match(
[store.state.a], /* pattern */
[1], /* match */
);
// ИЛИ
const subscription = a.filter(s => s === 1)
// or, we need all `b`
// only when `a` equal `1`
var subscriptionStatic = match(
[store.state.a, store.state.b],
[1],
);
// ИЛИ
const subscription = combineLatest([a, b]).filter(([a]) => a === 1)
// or, we just need `b`
var subscriptionStatic = match(
[store.state.b],
);
// ИЛИ
const subscription = b // %)
// dynamic initialization subscription
const subscriptionDynamicFromInitialization = match(props => [
[store.state.a],
[props.a],
]);
// ИЛИ
const subscriptionDynamic = props => a.filter(s => s === props.a)
// И так далее
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment