Helper which yields a function that transitions to the specified state
503112
function setState(state) {
        return function (job, arg0, arg1) {
            job._setState(state, arg0, arg1);
        };
    }
655014
def transition(field, source='*', target=None, on_error=None, conditions=[], permission=None, custom={}):
    
    def inner_transition(func):
        wrapper_installed, fsm_meta = True, getattr(func, '_django_fsm', None)
        if not fsm_meta:
            wrapper_installed = False
            fsm_meta = FSMMeta(field=field, method=func)
            setattr(func, '_django_fsm', fsm_meta)

        if isinstance(source, (list, tuple, set)):
            for state in source:
                func._django_fsm.add_transition(func, state, target, on_error, conditions, permission, custom)
        else:
            func._django_fsm.add_transition(func, source, target, on_error, conditions, permission, custom)

        @wraps(func)
        def _change_state(instance, *args, **kwargs):
            return fsm_meta.field.change_state(instance, func, *args, **kwargs)

        if not wrapper_installed:
            return _change_state

        return func

    return inner_transition
995404
function _switchState(state) {
            // clear previous interval if any
            _stopRunLoop();

            // call the stage destroy method
            if (_stages[_state]) {
                // just notify the object
                _stages[_state].stage.destroy();
            }

            if (_stages[state]) {
                // set the global variable
                _state = state;

                // call the reset function with _extraArgs as arguments
                _stages[_state].stage.reset.apply(_stages[_state].stage, _extraArgs);

                // and start the main loop of the
                // new requested state
                _startRunLoop();

                // execute callback if defined
                if (_onSwitchComplete) {
                    _onSwitchComplete();
                }

                // force repaint
                me.game.repaint();
            }
        }
406026
function (state) {

            if (typeof state === 'boolean') {
                return state ? this.show() : this.hide();
            }
            this.each(function () {
                if (isHidden(this)) {
                    showHide(this, true);
                } else {
                    showHide(this);
                }
            });
            return this;
        }
917033
function switches() {
  return fritz.getSwitchList().then(function(switches) {
    console.log("Switches: " + switches + "\n");

    return sequence(switches.map(function(sw) {
      return function() {
        return sequence([
          function() {
            return fritz.getSwitchName(sw).then(function(name) {
              console.log("[" + sw + "] " + name);
            });
          },
          function() {
            return fritz.getSwitchPresence(sw).then(function(presence) {
              console.log("[" + sw + "] presence: " + presence);
            });
          },
          function() {
            return fritz.getSwitchState(sw).then(function(state) {
              console.log("[" + sw + "] state: " + state);
            });
          },
          function() {
            return fritz.getTemperature(sw).then(function(temp) {
              temp = isNaN(temp) ? '-' : temp + "°C";
              console.log("[" + sw + "] temp: " + temp + "\n");
            });
          }
        ]);
      };
    }));
  });
}
1334053
function () {
            /*  special case: just retrieve current state  */
            var state_old = _cs.states[this.__state].state;
            if (arguments.length === 0)
                return state_old;

            /*  determine parameters  */
            var params = $cs.params("state", arguments, {
                state:    { pos: 0, req: true,
                            valid: function (s) { return _cs.state_name2idx(s) !== -1; } },
                func:     { pos: 1, def: undefined },
                min:      {         def: undefined },
                max:      {         def: undefined },
                sync:     {         def: false     }
            });

            /*  if requested state is still not reached...  */
            var sOld = this.__state;
            var sNew = _cs.state_name2idx(params.state);
            if (   ( params.min === true && !params.max          && sNew  >  sOld)
                || (!params.min          &&  params.max === true && sNew  <  sOld)
                || ( params.min === true &&  params.max === true && sNew !== sOld)
                || (!params.min          && !params.max          && sNew !== sOld)) {
                var enqueue = true;
                var cid     = this.id();
                var request = {
                    comp:     this,
                    state:    params.state
                };

                /*  handle the params.func callback using await  */
                if (typeof params.func === "function" && _cs.states.length > 1) {
                    this.await({
                        state:     params.state,
                        direction: (sNew > sOld ? "upward" : "downward"),
                        func:      params.func,
                        spool:     _cs.states[1].state /* the first state after "dead" */
                    });
                }
                if (params.sync) {
                    /*  perform new state transition request (synchronously)  */
                    if (_cs.state_progression_single(request))
                        enqueue = false;

                    /*  delete any old transition request  */
                    if (_cs.state_requests[cid])
                        delete _cs.state_requests[cid];
                }
                if (enqueue) {
                    /*  enqueue new state transition request and trigger
                        state transition progression (asynchronously)  */
                    _cs.state_requests[cid] = request;
                    _cs.hook("ComponentJS:state-invalidate", "none", "requests");
                    _cs.state_progression();
                }
            }
            else {
                /*  still run its optional callback function  */
                if (typeof params.func === "function")
                    params.func.call(this, params.state);
            }

            /*  return old (and perhaps still current) state  */
            return state_old;
        }
111906
function refreshState(){
		self._possibleTransitions = [];
		for(var transitionIndex = 0; transitionIndex < self._states[self._currentState].transitions.length; ++transitionIndex){
			var transition = self._states[self._currentState].transitions[transitionIndex];
			// Initialize the new variable that we'll push() onto _possibleTransitions later.
			var possibleTransition = {
				destination: transition.destination,
				action: transition.action,
				outputEventType: transition.outputEventType,
				remainingEvents: []
			};
			// Populate the list of remaining events that will be subsequently decreased, until it hits a count of zero, at which point this particular transition takes place.
			for(var eventIndex = 0; eventIndex < transition.requiredEvents.length; ++eventIndex){
				// Place the event specification into the list of remaining events.
				var event = transition.requiredEvents[eventIndex];
				possibleTransition.remainingEvents.push(event);
			}
			// Now that the transition specification is complete, add it to the list of transitions possible from the current state.
			self._possibleTransitions.push(possibleTransition);
			// Additionally, if the spec contained an outputEventType (which overrides SagaStateTransitioned for initiating transitions), register a handler for that event type.
			if(possibleTransition.outputEventType){
				// Duplicate handlers are checked, in order to avoid double state refresh (which would result in excessive event handler populations -> memory leak via avalanche effect after a few transitions).
				//  This check is somewhat strange due to EventEmitter's listener function wrapping when using once().
				if(!self.listeners(possibleTransition.outputEventType).some(function(listenerFunction){ return listenerFunction === applyTransition || listenerFunction.listener === applyTransition; })){
					// The listener is not yet present, so add it.
					self.once(possibleTransition.outputEventType, applyTransition);
				}
			}
		}
	}
152413
def transition(trname='', field='', check=None, before=None, after=None):
    """"""
    if is_callable(trname):
        raise ValueError(
            "The @transition decorator should be called as "
            "@transition(['transition_name'], **kwargs)")
    if check or before or after:
        warnings.warn(
            "The use of check=, before= and after= in @transition decorators is "
            "deprecated in favor of @transition_check, @before_transition and "
            "@after_transition decorators.",
            DeprecationWarning,
            stacklevel=2)
    return TransitionWrapper(trname, field=field, check=check, before=before, after=after)
393410
function(leaveState, event, data) {
        // If `data` is a string, it is the destination state of the transition
        if (_.isString(data)) data = {enterState: data}
        else data = _.clone(data)

        if (leaveState !== ANY_STATE && !this._states.hasOwnProperty(leaveState))
          this.state(leaveState, {})

        if (!this._states.hasOwnProperty(data.enterState))
          this.state(data.enterState, {})

        if (!this._transitions.hasOwnProperty(leaveState))
          this._transitions[leaveState] = {}

        data.callbacks = this._collectMethods((data.callbacks || []))
        this._transitions[leaveState][event] = data
      }
656347
def PopState(self, **unused_kwargs):
    """"""
    try:
      self.state = self.state_stack.pop()
      logging.debug('Returned state to {0:s}'.format(self.state))

      return self.state
    except IndexError:
      self.Error(
          'Tried to pop the state but failed - possible recursion error')
729181
def _transitionerFromInstance(oself, symbol, automaton):
    
    transitioner = getattr(oself, symbol, None)
    if transitioner is None:
        transitioner = Transitioner(
            automaton,
            automaton.initialState,
        )
        setattr(oself, symbol, transitioner)
    return transitioner
1252081
function() {
        if (this.state) {
          forEach(this.state.handlerInfos.slice().reverse(), function(handlerInfo) {
            var handler = handlerInfo.handler;
            callHook(handler, 'exit');
          });
        }

        this.state = new TransitionState();
        this.currentHandlerInfos = null;
      }
1279714
function ToggleAnimation (AppState) {
  var state = AppState.get()
  if (
    state.currentAnimation[0] === animationDictionary.bend[0] &&
    state.currentAnimation[1] === animationDictionary.bend[1]
  ) {
    state.currentAnimation = animationDictionary.jump
  } else {
    state.currentAnimation = animationDictionary.bend
  }

  AppState.set(state)
}
441437
function toggle(pos, state, ruleId) {
      var markers = ruleId ? scope[ruleId] : globals
      var currentState
      var previousState

      if (!markers) {
        markers = []
        scope[ruleId] = markers
      }

      previousState = getState(ruleId)
      currentState = state

      if (currentState !== previousState) {
        markers.push({state: currentState, position: pos})
      }

      /* Toggle all known rules. */
      if (!ruleId) {
        for (ruleId in scope) {
          toggle(pos, state, ruleId)
        }
      }
    }
183938
def _prepare_transition(self, is_on=None, **kwargs):
        
        # Handle transitions with changing on-off-state
        dest_state = kwargs.copy()
        if is_on is not None:
            if is_on and not self.is_on:
                if 'brightness' not in kwargs or kwargs['brightness'] is None:
                    dest_state['brightness'] = self.brightness
                self.set(brightness=0, cancel_transition=False)
            elif not is_on and self.is_on:
                dest_state['brightness'] = 0

        return dest_state
1233033
def transition_to(path, current_state=self.current_state)
      path = path.to_s
      state = current_state || self
      exit_states = []

      # Find the nearest parent state on the path of the current state which
      # has a sub-state at the given path
      new_states = state.find_states(path)
      while(!new_states) do
        exit_states << state
        state = state.parent_state
        raise(StateNotFound, transition_error(path)) unless state
        new_states = state.find_states(path)
      end

      # The first time we enter a state, the state_manager gets entered as well
      new_states.unshift(self) unless has_state?

      # Can only transition to leaf states
      # TODO: transition to the initial_state of the state?
      raise(InvalidTransition, transition_error(path)) unless new_states.last.leaf?

      enter_states = new_states - exit_states
      exit_states = exit_states - new_states

      from_state = current_state
      # TODO: does it make more sense to throw an error instead of allowing
      # a transition to the current state?
      to_state = enter_states.last || from_state

      run_before_callbacks(from_state, to_state, current_event, enter_states, exit_states)

      # Set the state on the underlying resource
      self.current_state = to_state

      run_after_callbacks(from_state, to_state, current_event, enter_states, exit_states)
    end
932294
function() {
        if (!this.transitions) return

        var leaveState, event, transitions = this.transitions
        for (leaveState in transitions)
          for (event in transitions[leaveState])
            this.transition(leaveState, event, transitions[leaveState][event])

        if (!(transitions.hasOwnProperty(INIT_STATE)
          || transitions.hasOwnProperty(ANY_STATE)) && typeof console !== 'undefined')
          console.warn('there is no transition from state "init" to another state.')
      }