npm.io
0.0.7 • Published 6 years ago

mobx-method-decorators

Licence
MIT
Version
0.0.7
Deps
1
Size
11 kB
Vulns
0
Weekly
0

Node.js CI

mobx-method-decorators

  • Assist reaction(...) calling with class-oriented way.

How to use?

isntall

yarn add mobx-method-decorators
write code
import mobx from 'mobx';
import { ReactableMixin, reactionMethod } from 'mobx-method-decorators';

const store = mobx.observable({
  message: 'Hello world.',
});

class Sample extends ReactableMixin {
  constructor() {
    this.makeReactable();
  }

  @reactionMethod(() => store.message)
  method() {
    // Execute whenever store.message changed.
  }

  detach() {
    // Dispose any reactions, call `unmakeReactable`
    this.unmakeReactable();
  }
}

MIT