src/store.js
function setSingle(store, key, value, flag) {
  const { _store, _subscriptions } = store

  // Uncurry alfa action functions
  if (typeof value === 'function' && value.alfaAction) {
    value = value.alfaAction(store)
  }

  // Save the value to the store.
  _store[key] = value

  if (flag === 'merge') {
    return
  }

  // Call subscribed functions if we have.
  const subs = _subscriptions[key]
  if (subs) {
    var changed = {
      [key]: value
    }

    subs.forEach(function(subFn) {
      // Make sure the subFn is still legit at the time we are calling it since
      // all subscribing functions are actually `setStat`.  And previous
      // `setState` calls could trigger unmount component which later `setState`
      // belongs to.

      // Need to make the below code reproducible by test.
      // var _subs = subscriptions[key]
      // if (_subs.indexOf(subFn) === -1) {
      //   return
      // }

      if (subFn.maps) {
        var maps = subFn.maps
        Object.keys(maps).some(function(injectKey) {
          const realKey = maps[injectKey]
          if (realKey === key) {
            changed = {
              [injectKey]: value
            }
            return true
          }
          return false
        })
      }
      subFn(changed)
    })
  }
}
function setSingle(store, key, value, flag) {
  const { _store, _subscriptions } = store

  // Uncurry alfa action functions
  if (typeof value === 'function' && value.alfaAction) {
    value = value.alfaAction(store)
  }

  // Save the value to the store.
  _store[key] = value

  if (flag === 'merge') {
    return
  }

  // Call subscribed functions if we have.
  const subs = _subscriptions[key]
  if (subs) {
    var changed = {
      [key]: value
    }

    subs.forEach(function(subFn) {
      // Make sure the subFn is still legit at the time we are calling it since
      // all subscribing functions are actually `setStat`.  And previous
      // `setState` calls could trigger unmount component which later `setState`
      // belongs to.

      // Need to make the below code reproducible by test.
      // var _subs = subscriptions[key]
      // if (_subs.indexOf(subFn) === -1) {
      //   return
      // }

      if (subFn.maps) {
        var maps = subFn.maps
        Object.keys(maps).some(function(injectKey) {
          const realKey = maps[injectKey]
          if (realKey === key) {
            changed = {
              [injectKey]: value
            }
            return true
          }
          return false
        })
      }
      subFn(changed)
    })
  }
}
function setSingle ( store , key , value , flag ) { const { _store , _subscriptions } = store // Uncurry alfa action functions if ( typeof value === 'function' && value . alfaAction ) { value = value . alfaAction ( store ) } // Save the value to the store. _store [ key ] = value if ( flag === 'merge' ) { return } // Call subscribed functions if we have. const subs = _subscriptions [ key ] if ( subs ) { var changed = { [ key ] : value } subs . forEach ( function ( subFn ) { // Make sure the subFn is still legit at the time we are calling it since // all subscribing functions are actually `setStat`.  And previous // `setState` calls could trigger unmount component which later `setState` // belongs to. // Need to make the below code reproducible by test. // var _subs = subscriptions[key] // if (_subs.indexOf(subFn) === -1) { //   return // } if ( subFn . maps ) { var maps = subFn . maps Object . keys ( maps ) . some ( function ( injectKey ) { const realKey = maps [ injectKey ] if ( realKey === key ) { changed = { [ injectKey ] : value } return true } return false } ) } subFn ( changed ) } ) } }
Set a single value to an object.
Set a single value to an object .