javascript 无国籍的Redux

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 无国籍的Redux相关的知识,希望对你有一定的参考价值。

var createStore = function(stateModifiers) {
  var localState = {
    subscribers: [],
  }

  var subscribe = function(subscribers) {
    localState
    .subscribers = (
      localState
      .subscribers
      .concat(subscribers)
    )
    
    return {
      unsubscribe: function() {
        subscribers
        .forEach(function(subscriber) {
          const index = (
            localState
            .subscribers
            .indexOf(subscriber)
          )
          
          localState
          .subscribers
          .splice(index, 1)
        })
      }
    }
  }
  
  var createDispatch = function(stateModifiers) {
    return function(action) {
      if (!action.type) {
        console
        .error(
            "No type for action",
            action,
        )
      }

      if (window.__isDebugging) {
        console
        .info(
          action.type,
          action,
        )
      }

      stateModifiers[action.type]
      && stateModifiers[action.type](action)

      localState
      .subscribers
      .forEach(function(subscriber) {
        subscriber(action)
      })

      return action
    }
  }
  
  return {
    dispatch: createDispatch(stateModifiers),
    subscribe: subscribe,
  }
}

以上是关于javascript 无国籍的Redux的主要内容,如果未能解决你的问题,请参考以下文章

javascript 无状态Redux减速机

javascript 无状态Redux-Observable

javascript 用于调试无状态Redux-Observable的Action Logger

分配器无国籍意味着什么?

Spring Security:能满足这些要求吗?无国籍?无会话?要么?

OAuth 2.0。没有会议? (无国籍)