Skip to content

Instantly share code, notes, and snippets.

@vivainio
Created December 22, 2017 16:40
Show Gist options
  • Select an option

  • Save vivainio/b5f936a69d22a13aa933256877f72e0f to your computer and use it in GitHub Desktop.

Select an option

Save vivainio/b5f936a69d22a13aa933256877f72e0f to your computer and use it in GitHub Desktop.
// don't like patching your components with custom hacks? use this!
class MobWrap {
unsubs: (() => void)[] = [];
constructor() {}
autorun(view: (r: IReactionPublic) => any, scope?: any) {
this.unsubs.push(realAutorun(view));
// "fluent" api for chaining stuff
return this;
}
reaction<T>(
expression: (r: IReactionPublic) => T,
effect: (arg: T, r: IReactionPublic) => void,
opts?: IReactionOptions
) {
this.unsubs.push(realReaction(expression, effect, opts));
return this;
}
stop() {
this.unsubs.forEach(f => f());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment