Giter VIP home page Giter VIP logo

mobx's Introduction

mobx原理解析

简介

对mobx的阉割版实现,提供autorunobservablecomputed

原理解析

observable

包装对象值的 Observable ,核心原理是 Object.defineProperty ,给被包装的属性套上 get 和 set 的钩子,在 get 中响应依赖收集,在 set 中触发监听函数。

observable原理图

autorun

在执行 autorun(handler) 的时候会执行以下的代码(实际上也就这三句代码):

dependences.dependencesCollectStart(func);
func();
dependences.dependencesCollectEnd();

这里 dependences 标记现在开始收集依赖,然后执行函数,执行结束之后,标记当前收集结束。 autorun原理图

computed

变种的autorun。

dependencesCollector

dependencesCollector原理图

运行测试用例

npm run test

mopx借鉴过的资料

基于@芋头君s-mobx进行复写改造,并且README.md中对mobx原理描述也截取了其中部分。

在此特别感谢以上各位提供的帮助,感谢对开源社区的贡献!

mobx's People

Contributors

shanamaid avatar

Stargazers

Nagisa avatar  avatar  avatar

Watchers

James Cloos avatar win avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.