How to use the mobx.observe function in mobx

To help you get started, we’ve selected a few mobx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ascoders / gaea-editor / gaea-editor / actions / viewport.ts View on Github external
onInit() {
        // 监听当前编辑组件变化
        observe(this.viewport, 'currentEditComponentMapUniqueKey', (newValue: string, oldValue: string) => {
            // 过 150 毫秒再显示编辑区域,不让动画被阻塞
            setTimeout(() => {
                this.viewport.showEditComponents = !!newValue
            }, 150)

            const selectClass = 'gaea-selected'

            // 把上一个元素选中样式置空
            if (oldValue !== null) {
                const prevEditDom = this.viewport.componentDomInstances.get(oldValue)
                if (hasClass(prevEditDom, selectClass)) {
                    removeClass(prevEditDom, selectClass)
                }
            }

            // 设置新元素为选中样式
github ckinmind / mobx-share / src / page-mobx / p9.js View on Github external
return null;
            }
            if (change.newValue.length === 6) {
                // 补全缺少的 '#' 前缀
                change.newValue = '#' + change.newValue;
                notification.warn({message: '警告提示', description: '缺少#前缀'});
                return change;
            }
            if (change.newValue.length === 7) {
                return change;
            }
            if (change.newValue.length > 10) this.disposer(); // 不再拦截今后的任何变化
            notification.error({message: '错误提示', description: change.newValue + ' 不是一个合法的颜色值'});
        });

        this.disposer2 = observe(this.style, 'color', (change) => {
            notification.success({message: '颜色设置成功', description:
                `更新类型:${change.type}, 
                 输入的值:${change.newValue},
                 旧的值:${change.oldValue}
            `});
        });

    }
github sagivo / StockStalk / src / Fetcher.js View on Github external
async setup() {
    const intervals = [];

    // update icon only on mac
    if (window.process.platform === 'darwin') {
      intervals.push(observe(this.props.store.userStore, 'portfolio', async change => {
        const { portfolio } = this.props.store.userStore;
        this.props.store.userStore.prevEquity = change.oldValue.equity;
        // set image
        const image = new Jimp(100, 20);
        const font = await Jimp.loadFont(Jimp.FONT_SANS_14_BLACK);
        const text = `${num(portfolio.todayChangePercent, { after: '%' })}`;
        image.print(font, 5, 0, text);
        image.color([ { apply: portfolio.todayChange >= 0 ? 'green' : 'red', params: [ 180 ] } ]);
        image.crop(0, 0, text.length * 10, 20);
        image.write(trayImagePath, () => ipcRenderer.send('msg', { type: 'tray' }));
      }));
    }

    await this.updatePositions();
    await this.updateStocks();
github foxhound87 / mobx-react-form / src / Form.js View on Github external
on(event, callback) {
    observe(Events.getRunning(), ({ name, oldValue, object }) => {
      if (!event.includes('@')) return;

      const $event = _.split(event, '@');
      const $path = Events.path(name);

      if ($event[0] === name
        && $event[1] === $path
        && oldValue && !object[name]) {
        callback({ form: this, path: $path });
      }
    });
  }
github infinitered / reactotron / legacy / reactotron-cli / src / ui / reactions.js View on Github external
const subscribe = ({command, handler}) => {
    observe(server.commands[command], ({added}) => {
      const draw = ({payload}) => handler(payload)
      R.forEach(draw, added)
    })
  }
github Raathigesh / wiretap / packages / lib / src / mobxTracker.js View on Github external
observableArray.forEach(observableItem => {
    const disposer = observe(observableItem, change => {
      emitChange({
        id,
        isMobx: true,
        value: toJS(thingToEmit),
        action: change
      });
    });
    arrayItemObserverDisposables.push(disposer);
  });
github NeutroniumCore / Neutronium / JavascriptFramework / Neutronium.JavascriptFramework.mobx / script / src / index.js View on Github external
function updateListenerElement(element, listener) {
    listener.watch = observe(element.father, (change) => {
        listener.callback(change.name, change.newValue)
    })
}
github fox-finder / FoxFinder / src / bases / features / tooltip / index.tsx View on Github external
watchTypeChange() {
    observe(
      computed(() => this.activeContentType),
      ({ newValue, oldValue }) => {
        this.handleTypeChange(newValue, oldValue as ActiveContentTypeValue)
      }
    )
  }