connect a React component's state to keys in the global store.
When a watched key of the store is updated, that the component's
setState method will be called.
Call this from the Component's constructor:
store.connectComponentState(this, ['key1', 'key2'])
510909
function connectComponentState(component, keys_to_watch_for_changes) {
    var additonal_callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;

    if (!Array.isArray(keys_to_watch_for_changes)) {
      throw keys_to_watch_for_changes + ' must be an array';
    }
    component.state = component.state || {}; // initialize if not set

    // call this function whenever the store changes
    function _callback(changed_keys) {
      if (intersection(keys_to_watch_for_changes, changed_keys).length) {
        // only update the state if a key we care about has changed
        var state_update_obj = {};
        keys_to_watch_for_changes.forEach(function (k) {
          return state_update_obj[k] = store._store[k];
        });
        this.setState(state_update_obj);

        // if some other custom callback is required by the component
        // call that function as well
        if (additonal_callback) {
          additonal_callback(changed_keys);
        }
      }
    }
    var callback_bound_to_component = _callback.bind(component);

    // add keys that map to the store's keys
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = keys_to_watch_for_changes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var k = _step.value;

        if (!store._store.hasOwnProperty(k)) {
          throw 'Store does not have key ' + k;
        }
        if (component.state.hasOwnProperty(k)) {
          console.warn('Overwriting existing state key ' + k);
        }
        component.state[k] = store._store[k];

        store._recordKeySubscriber(k, component.constructor.name);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    return store.subscribe(callback_bound_to_component);
  }
323507
function (property, store) {

      if (!isStore(store)) {
        throw new Error('Store expected');
      }

      var _this = this;

      store.onChange(function () {
        if (property) {
          _this.setState(property, store.state);
        } else {
          _this.setState(store.state);
        }
      });

      this.onReset(function () {
        store.resetState();
      });

      this.on('storeWillMount', function () {
        store.replaceProps(_this.props);
        store.emit('storeWillMount');
      });

      this.on('storeWillUnmount', function () {
        store.emit('storeWillUnmount');
        store.replaceProps(_this.props);
      });

      this.on('storeWillReceiveProps', function () {
        store.replaceProps(_this.props);
        store.emit('storeWillReceiveProps');
      });
    }
297265
def set_state(self, newState, timer=0):
        """"""
        if _debug: SSM._debug("set_state %r (%s) timer=%r", newState, SSM.transactionLabels[newState], timer)

        # make sure we have a correct transition
        if (self.state == COMPLETED) or (self.state == ABORTED):
            e = RuntimeError("invalid state transition from %s to %s" % (SSM.transactionLabels[self.state], SSM.transactionLabels[newState]))
            SSM._exception(e)
            raise e

        # stop any current timer
        self.stop_timer()

        # make the change
        self.state = newState

        # if another timer should be started, start it
        if timer:
            self.start_timer(timer)
1243483
function sendConcurrent() {
    var args = slice.call(arguments), handled = true, state, i, n;

    for (i = 0, n = this.substates.length; i < n; i++) {
      state   = this.substates[i];
      handled = send.apply(state, args) && handled;
    }

    return handled;
  }
164895
function PolymerRedux(store) {
  if (!store) {
    throw new TypeError('PolymerRedux: expecting a redux store.');
  } else if (!['getState', 'dispatch', 'subscribe'].every(function (k) {
    return typeof store[k] === 'function';
  })) {
    throw new TypeError('PolymerRedux: invalid store object.');
  }

  var subscribers = new Map();

  /**
   * Binds element's properties to state changes from the Redux store.
   *
   * @example
   *     const update = bind(el, props) // set bindings
   *     update(state) // manual update
   *
   * @private
   * @param {HTMLElement} element
   * @param {Object} properties
   * @return {Function} Update function.
   */
  var bind = function bind(element, properties) {
    var bindings = Object.keys(properties).filter(function (name) {
      var property = properties[name];
      if (Object.prototype.hasOwnProperty.call(property, 'statePath')) {
        if (!property.readOnly && property.notify) {
          console.warn('PolymerRedux: <' + element.constructor.is + '>.' + name + ' has "notify" enabled, two-way bindings goes against Redux\'s paradigm');
        }
        return true;
      }
      return false;
    });

    /**
     * Updates an element's properties with the given state.
     *
     * @private
     * @param {Object} state
     */
    var update = function update(state) {
      var propertiesChanged = false;
      bindings.forEach(function (name) {
        // Perhaps .reduce() to a boolean?
        var statePath = properties[name].statePath;

        var value = typeof statePath === 'function' ? statePath.call(element, state) : (0, _path.get)(state, statePath);

        var changed = element._setPendingPropertyOrPath(name, value, true);
        propertiesChanged = propertiesChanged || changed;
      });
      if (propertiesChanged) {
        element._invalidateProperties();
      }
    };

    // Redux listener
    var unsubscribe = store.subscribe(function () {
      var detail = store.getState();
      update(detail);

      element.dispatchEvent(new window.CustomEvent('state-changed', { detail: detail }));
    });

    subscribers.set(element, unsubscribe);

    return update(store.getState());
  };

  /**
   * Unbinds an element from state changes in the Redux store.
   *
   * @private
   * @param {HTMLElement} element
   */
  var unbind = function unbind(element) {
    var off = subscribers.get(element);
    if (typeof off === 'function') {
      off();
    }
  };

  /**
   * Merges a property's object value using the defaults way.
   *
   * @private
   * @param {Object} what Initial prototype
   * @param {String} which Property to collect.
   * @return {Object} the collected values
   */
  var collect = function collect(what, which) {
    var res = {};
    while (what) {
      res = Object.assign({}, what[which], res); // Respect prototype priority
      what = Object.getPrototypeOf(what);
    }
    return res;
  };

  /**
   * ReduxMixin
   *
   * @example
   *     const ReduxMixin = PolymerRedux(store)
   *     class Foo extends ReduxMixin(Polymer.Element) { }
   *
   * @polymerMixinClass
   *
   * @param {Polymer.Element} parent The polymer parent element.
   * @return {Function} PolymerRedux mixed class.
   */
  return function (parent) {
    return function (_parent) {
      _inherits(ReduxMixin, _parent);

      function ReduxMixin() {
        _classCallCheck(this, ReduxMixin);

        // Collect the action creators first as property changes trigger
        // dispatches from observers, see #65, #66, #67
        var _this = _possibleConstructorReturn(this, (ReduxMixin.__proto__ || Object.getPrototypeOf(ReduxMixin)).call(this));

        var actions = collect(_this.constructor, 'actions');
        Object.defineProperty(_this, '_reduxActions', {
          configurable: true,
          value: actions
        });
        return _this;
      }

      _createClass(ReduxMixin, [{
        key: 'connectedCallback',
        value: function connectedCallback() {
          _get(ReduxMixin.prototype.__proto__ || Object.getPrototypeOf(ReduxMixin.prototype), 'connectedCallback', this).call(this);
          var properties = collect(this.constructor, 'properties');
          bind(this, properties);
        }
      }, {
        key: 'disconnectedCallback',
        value: function disconnectedCallback() {
          _get(ReduxMixin.prototype.__proto__ || Object.getPrototypeOf(ReduxMixin.prototype), 'disconnectedCallback', this).call(this);
          unbind(this);
        }

        /**
         * Dispatches an action to the Redux store.
         *
         * @example
         *     element.dispatch({ type: 'ACTION' })
         *
         * @example
         *     element.dispatch('actionCreator', 'foo', 'bar')
         *
         * @example
         *     element.dispatch((dispatch) => {
         *         dispatch({ type: 'MIDDLEWARE'})
         *     })
         *
         * @param  {...*} args
         * @return {Object} The action.
         */

      }, {
        key: 'dispatch',
        value: function dispatch() {
          var _this2 = this;

          for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          var actions = this._reduxActions;

          // Action creator
          var action = args[0];

          if (typeof action === 'string') {
            if (typeof actions[action] !== 'function') {
              throw new TypeError('PolymerRedux: <' + this.constructor.is + '> invalid action creator "' + action + '"');
            }
            action = actions[action].apply(actions, _toConsumableArray(args.slice(1)));
          }

          // Proxy async dispatch
          if (typeof action === 'function') {
            var originalAction = action;
            action = function action() {
              for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
                args[_key2] = arguments[_key2];
              }

              // Replace redux dispatch
              args.splice(0, 1, function () {
                return _this2.dispatch.apply(_this2, arguments);
              });
              return originalAction.apply(undefined, args);
            };

            // Copy props from the original action to the proxy.
            // see https://github.com/tur-nr/polymer-redux/issues/98
            Object.keys(originalAction).forEach(function (prop) {
              action[prop] = originalAction[prop];
            });
          }

          return store.dispatch(action);
        }

        /**
         * Gets the current state in the Redux store.
         *
         * @return {*}
         */

      }, {
        key: 'getState',
        value: function getState() {
          return store.getState();
        }
      }]);

      return ReduxMixin;
    }(parent);
  };
}
746037
function(component) {
    if (options.reduxStoreInitiator && isFunction(options.reduxStoreInitiator)) {
      var initStore = options.reduxStoreInitiator;
      if (initStore.default) {
        initStore = initStore.default;
      }
      var store = initStore(props);
      var Provider = require('react-redux').Provider;
      return React.createElement(Provider, { store: store }, component);
    } else {
      return component;
    }
  }
215276
function connect(Composed) {
  return (function (superclass) {
    function Connect(props) {
      superclass.call(this, props);
      this.state = getState();
      this.onChange = this.onChange.bind(this);
    }

    if ( superclass ) Connect.__proto__ = superclass;
    Connect.prototype = Object.create( superclass && superclass.prototype );
    Connect.prototype.constructor = Connect;

    Connect.prototype.componentDidMount = function componentDidMount () {
      this.token = subscribe(this.onChange);
    };

    Connect.prototype.componentWillUnmount = function componentWillUnmount () {
      if (typeof this.token === "function") {
        this.token();
      }
    };

    Connect.prototype.onChange = function onChange (state) {
      this.setState(state);
    };

    Connect.prototype.render = function render () {
      return React.createElement(Composed, Object.assign({}, this.state, this.props));
    };

    return Connect;
  }(React__default.PureComponent));
}
202422
void setState(KeyState newState) {
        if (MonocleSettings.settings.traceEvents) {
            MonocleTrace.traceEvent("Set %s", newState);
        }
        newState.getWindow(true);
        // send release events
        state.getKeysPressed().difference(keys, newState.getKeysPressed());
        if (!keys.isEmpty()) {
            for (int i = 0; i < keys.size(); i++) {
                int key = keys.get(i);
                dispatchKeyEvent(newState, KeyEvent.RELEASE, key);
            }
        }
        keys.clear();
        // send press events
        newState.getKeysPressed().difference(keys, state.getKeysPressed());
        if (!keys.isEmpty()) {
            for (int i = 0; i < keys.size(); i++) {
                int key = keys.get(i);
                if (key == KeyEvent.VK_CAPS_LOCK) {
                    capsLock = !capsLock;
                } else if (key == KeyEvent.VK_NUM_LOCK) {
                    numLock = !numLock;
                } else if (key == KeyEvent.VK_C && newState.isControlPressed()) {
                    AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
                        if ("1".equals(System.getenv("JAVAFX_DEBUG"))) {
                            System.exit(0);
                        }
                        return null;
                    });
                }
                dispatchKeyEvent(newState, KeyEvent.PRESS, key);
            }
        }
        keys.clear();
        newState.copyTo(state);
    }
1081016
function _callback(changed_keys) {
      if (intersection(keys_to_watch_for_changes, changed_keys).length) {
        // only update the state if a key we care about has changed
        var state_update_obj = {};
        keys_to_watch_for_changes.forEach(function (k) {
          return state_update_obj[k] = store._store[k];
        });
        this.setState(state_update_obj);

        // if some other custom callback is required by the component
        // call that function as well
        if (additonal_callback) {
          additonal_callback(changed_keys);
        }
      }
    }
557258
function(options) {
        this._transitions = {}
        this._states = {}
        options = options || {}
        this._bindStates()
        this._bindTransitions()
        if (options.debugStateMachine === true)
          StateMachine.DebugView.register(this)
        this.bind('all', this._onMachineEvent, this)
        this.currentState = INIT_STATE
        this.startStateMachine = function() {
          throw new Error('startStateMachine has been called twice!')
        }
      }
472187
function ConnectionState(code, stringId, connected) {
  if (arguments.length === 2) {
    connected = stringId;
    stringId = 'NONAME';
  }
  if (!(this instanceof ConnectionState)) {
    return new ConnectionState(code, stringId, connected);
  }

  this.id = stringId;
  this.code = code;
  this.connected = connected;
}
262046
function subscribeToKeys(keys_to_watch_for_changes, callback) {
    if (!Array.isArray(keys_to_watch_for_changes)) {
      throw keys_to_watch_for_changes + ' must be an array';
    }

    // add keys that map to the store's keys
    var _iteratorNormalCompletion2 = true;
    var _didIteratorError2 = false;
    var _iteratorError2 = undefined;

    try {
      for (var _iterator2 = keys_to_watch_for_changes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
        var k = _step2.value;

        if (!store._store.hasOwnProperty(k)) {
          throw 'Store does not have key ' + k;
        }
        store._recordKeySubscriber(k, callback.name);
      }

      // call this function whenever the store changes
    } catch (err) {
      _didIteratorError2 = true;
      _iteratorError2 = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion2 && _iterator2.return) {
          _iterator2.return();
        }
      } finally {
        if (_didIteratorError2) {
          throw _iteratorError2;
        }
      }
    }

    function _callback(changed_keys) {
      if (intersection(keys_to_watch_for_changes, changed_keys).length) {
        callback(changed_keys);
      }
    }
    return store.subscribe(_callback);
  }
297474
synchronized boolean updateKeystoreConfig(Dictionary<String, Object> props) {
        properties = props;
        if (id != null) {
            properties.put(Constants.SSLPROP_ALIAS, id);
        }
        String location = (String) properties.get(LibertyConstants.KEY_KEYSTORE_LOCATION);
        if (location != null) {
            properties.put(Constants.SSLPROP_KEY_STORE, locSvc.getServiceWithException().resolveString(location));
        }

        try {
            // Try modifying the properties..
            // This may throw if arguments are bad
            wsKeyStore = new WSKeyStore(id, properties, this);
            KeyStoreManager.getInstance().addKeyStoreToMap(id, wsKeyStore);
            KeyStoreManager.getInstance().addKeyStoreToMap(pid, wsKeyStore);
            return true;
        } catch (Exception e) {
            wsKeyStore = null;
            return false;
        }
    }
1071501
def send_state(self, key=None):
        
        state = self.get_state(key=key)
        if len(state) > 0:
            if self._property_lock:  # we need to keep this dict up to date with the front-end values
                for name, value in state.items():
                    if name in self._property_lock:
                        self._property_lock[name] = value
            state, buffer_paths, buffers = _remove_buffers(state)
            msg = {'method': 'update', 'state': state, 'buffer_paths': buffer_paths}
            self._send(msg, buffers=buffers)
254635
function updateState( targetState ) {
            const state = axVisibility.isVisible();
            if( state === lastState ) {
               return;
            }
            lastState = state;
            heartbeat.onAfterNext( () => {
               const handlers = targetState ? showHandlers : hideHandlers;
               handlers.forEach( f => f( targetState ) );
            } );
         }
1074456
void connect(Object from, String from_out, Object to, String to_in) {
        // add them to the set of commands
        if (from == to) {
            throw new ComponentException("src == dest.");
        }
        if (to_in == null || from_out == null) {
            throw new ComponentException("Some field arguments are null");
        }

        ComponentAccess ca_from = lookup(from);
        ComponentAccess ca_to = lookup(to);

        Access from_access = ca_from.output(from_out);
        checkFA(from_access, from, from_out);
        Access to_access = ca_to.input(to_in);
        checkFA(to_access, to, to_in);

        if (!canConnect(from_access, to_access)) {
            throw new ComponentException("Type/Access mismatch, Cannot connect: " + from + '.' + to_in + " -> " + to + '.' + from_out);
        }

        // src data object
        FieldContent data = from_access.getData();
        data.tagIn();
        data.tagOut();

        dataSet.add(data);
        to_access.setData(data);                       // connect the two

        if (checkCircular) {
            validator.addConnection(from, to);
            validator.checkCircular();
        }

        if (log.isLoggable(Level.CONFIG)) {
            log.config(String.format("@Out(%s) -> @In(%s)", from_access.toString() , to_access.toString()));
        }

//        ens.fireConnect(from_access, to_access);
    }
622633
def when_change(
        self,
        *keys: Hashable,
        exclude: bool = False,
        live: bool = False,
        timeout: float = None,
        identical_okay: bool = False,
        start_time: bool = None,
        count: int = None,
    ) -> StateWatcher:
        
        if not keys:

            def callback(update: StateUpdate) -> dict:
                return update.after

        else:
            if identical_okay:
                raise ValueError(
                    "Passing both `identical_okay` and `keys` is not possible. "
                    "(Hint: Omit `keys`)"
                )

            key_set = set(keys)

            def select(before, after):
                selected = {*before.keys(), *after.keys()}
                if exclude:
                    return selected - key_set
                else:
                    return selected & key_set

            def callback(update: StateUpdate) -> dict:
                before, after = update.before, update.after
                try:
                    if not any(before[k] != after[k] for k in select(before, after)):
                        raise _SkipStateUpdate
                except KeyError:  # this indirectly implies that something has changed
                    pass
                return update.after

        return StateWatcher(
            state=self,
            live=live,
            timeout=timeout,
            identical_okay=identical_okay,
            start_time=start_time,
            count=count,
            callback=callback,
        )