Giter Site home page Giter Site logo

redux-analysis's Introduction

  • 👋 Hi, I’m @alan89757
  • 👀 I’m interested in react/vue/nodejs
  • 🌱 I’m currently learning react
  • 💞️ I’m looking to collaborate on bussiness
  • 📫 How to reach me e-mail: [email protected]

redux-analysis's People

Contributors

alan89757 avatar

Watchers

 avatar  avatar

redux-analysis's Issues

redux和flux的区别是什么?

Flux:
Store 包含状态和更改逻辑
有多个 Store
所有 Store 都互不影响且是平级的
有单一调度器
React 组件订阅 store
状态是可变的

Redux:
Store 和更改逻辑是分开的
只有一个 Store
带有分层 reducer 的单一 Store
没有调度器的概念
容器组件是有联系的
状态是不可改变的

Redux和vuex有什么区别?

1:vuex的异步数据不需要使用到中件间,redux需要
2:vuex可以直接commit,action不是必须的,redux是必须的

redux-saga和redux-thunk有什么本质的区别?

saga 自己基本上完全弄了一套 asyc 的事件监听机制。虽然好的一方面是将来可以扩展成 worker 相关的模块,甚至可以做到 multiple threads 同时执行,但代码量大大增加。如果只是普通的 application,用 redux-thunk 足够。
redux-thunk 是 2015-7-13 发布的第一个版本,而 redux-saga 是 2015-12-2 发布的第一个版本。他们基本上都是在同一年被创造出来。

Mobx和Redux有什么区别?

Redux的编程范式是函数式的而Mobx是面向对象的;
从数据上来说Redux每次都返回一个新的数据,而Mobx从始至终都是一份引用。因此Redux是支持数据回溯的;
和Redux相比,使用Mobx的组件可以做到精确更新,这一点得益于Mobx的observable;对应的,Redux是用dispath进行广播,通过Provider和connect来比对前后差别控制更新粒度;Mobx更加精细一点。

Redux怎样设置初始状态?

// createStore的第二个参数:

const rootReducer = combineReducers({
  todos: todos,
  visibilityFilter: visibilityFilter
});

const initialState = {
  todos: [{id:123, text:'hello', completed: false}]
};

const store = createStore(
  rootReducer,
  initialState
);

在redux中,什么是reducer?它有什么作用?

reducer的作用 :
根据 action 对象的type 来更新状态.

reducer的工作方式 :
接收一个 state 参数, 作为初始的 state
接收一个action对象, 在函数体中用 switch 语句 判断 action 的type, 然后定义相应的处理方式( 返回新的 state 对象) .

[react] Context api可以取代Redux吗?为什么?

暂时不会,原因是利大于弊。关于利,createContext 从能力上只比 组件context 多一个能力,就是当父组件实现了shouldComponentUpdate return false时,子组件也可以更新 context value。

但多了这个功能的要付出代价却不小,新的createcontext 使用上必须先引用,比如在皮肤机制里对编码的约束会有些大,尤其在多人协作时,没有原先来的便利。

另外redux另一个关键概念是store,而react不太可能会去新加createStore。

Redux的中间件是什么?你有用过哪些Redux的中间件?

view在redux中会派发一个action,action通过store的dispatch方法派发给store,store接收到action连同之前老的state一起传给reducer,reducer返回新的数据给store,store去改变自己的state,这是redux的流程。

redux中间件的中间指的是action和store之间,之前在redux中action只能返回一个对象,所以action返回的一个对象会直接派发给store,现在使用redux-thunk之后action可以返回一个函数了,action通过dispatch方法被传递给store,那么action和store之间就是dispatch这个方法。

实际上中间件就是对dispatch方法的一个封装或者说对dispatch方法的一个升级,最原始的dispatch方法接收到一个对象之后会把这个对象传递给store。

当把dispatch做了升级之后,比如说使用了redux-thunk 这个中间件,这个时候当调用dispatch方法给dispatch方法传递的参数是一个对象的话,那么dispatch就会把这个对象直接传递给store,跟之前我们写dispatch传递给它一个对象没什么区别,但是如果传递给dispatch方法是一个函数的话,这个时候dispatch已经升级了,它就不会把这个函数直接传递给store,它会先让这个函数执行,执行完了之后需要调用store的时候再去调用store。所以dispatch在这里会根据参数的不同执行不同的事情。

所以redux的中间件就是对store的dispatch做了个升级,升级之后dispatch就可以对象和函数都可以接收了。

当然中间件不止redux-thunk 这一个,实际上redux的中间件很多,比如redux-logger,redux-saga。redux-saga也是解决redux中异步问题的中间件,redux-thunk是把异步操作放在action里操作,而redux-saga的设计**是把异步操作单独拆分出来放在一个文件里管理。

redux的thunk作用是什么?

redux-thunk的作用:不使用中间件的情况,action只能是个对象,thunk帮助我们异步请求数据给store

说说Redux的实现流程

组件视图 通过 事件 发送 dispatch action
store 接收到 action , 把action和 oldState 当做参数发送给 reducers
reducers 接收 action和 oldState 通过计算返回新的 newState 给 store
store 会把 state 重新渲染到组件内视图

你有了解Rxjs是什么吗?它是做什么的?

RxJS 是一个库,它通过使用 observable 序列来编写异步和基于事件的程序。它提供了一个核心类型 Observable,附属类型 (Observer、 Schedulers、 Subjects) 和受 [Array#extras] 启发的操作符 (map、filter、reduce、every, 等等),这些数组操作符可以把异步事件作为集合来处理。

可以把 RxJS 当做是用来处理事件的 Lodash 。

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.