Giter Site home page Giter Site logo

data-response's Introduction

title date draft
响应式原理
2021-05-20 12:09:55 +0800
true

响应式原理

官方响应式原理图

核心函数说明

手写源码,函数模块调用流程图

observe

  • 在对象上添加__ob__属性,这个属性指向一个Observer侦测对象

Observer

  • 侦测类,作用是将对象的每一层转为响应式
  • dep类的实例在此类中实例化,用来收集依赖Watcher的实例

defineReactive

  • 两个核心getter和setter
  • 在getter中收集依赖(主要看Dep.target是否不为空,不为空就说明目前有依赖,多个依赖竞争Dep.target)
  • 在setter中触发依赖

parsePath

  • 将字符串路径,例如'a.b.c.d',转为能够在原对象上读取此路径对应的值的函数

array

  • 改写Array.prototype上的七个函数,让它们变为响应式

改写流程图

  • 在arrayMethods定义七个一模一样的api,并重写覆盖Array.prototype上的这七个api。再将数组实例的原型设置为arrayMethods

github源码地址

手写数据响应式原理

data-response's People

Contributors

rocketturtlewqt avatar

Stargazers

 avatar

Watchers

 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.