event handlers - FSM: listen for events and reset state
498508
function onMouseDown( event ) {

		if ( scope.enabled === false ) return;

		event.preventDefault();

		if ( event.button === scope.mouseButtons.ORBIT ) {

			if ( scope.enableRotate === false ) return;

			handleMouseDownRotate( event );

			state = STATE.ROTATE;

		} else if ( event.button === scope.mouseButtons.ZOOM ) {

			if ( scope.enableZoom === false ) return;

			handleMouseDownDolly( event );

			state = STATE.DOLLY;

		} else if ( event.button === scope.mouseButtons.PAN ) {

			if ( scope.enablePan === false ) return;

			handleMouseDownPan( event );

			state = STATE.PAN;

		}

		if ( state !== STATE.NONE ) {

			document.addEventListener( 'mousemove', onMouseMove, false );
			document.addEventListener( 'mouseup', onMouseUp, false );

			scope.dispatchEvent( startEvent );

		}

	}
69970
def trigger(self, *args, **kwargs):
		
		current = self.name.split('/')
		while current:
			name = '/'.join(current)
			current.pop()
			if name in self.context.handlers:
				self.all_handlers += [(name, h) for h in self.context.handlers[name]] 
				if name == self.name:
					self.handlers += self.context.handlers[name]

		for name, handler in self.all_handlers:
			res = handler(self, *args, **kwargs)
			self.all_executed += 1
			self.all_result.append(res)
			if name == self.name:
				self.executed += 1
				self.result.append(res)
			if self.stopped:
				break

		self.all_handlers = [h for name, h in self.all_handlers]
971339
def process_event(self, event, client, args, force_dispatch=False):
        
        if not self.running:
            _log.debug("Ignoring '%s' event - controller not running.", event)
            return

        # We keep a copy of the state of loaded modules before this event,
        # and restore it when we're done. This lets us handle events that
        # result in other events being dispatched in a graceful manner.
        old_loaded = self.loaded_on_this_event
        self.loaded_on_this_event = set(old_loaded or []) if not force_dispatch else set()

        try:
            _log.debug("Controller is dispatching '%s' event", event)
            for module_name in self.module_ordering:
                if module_name in self.loaded_on_this_event and not force_dispatch:
                    _log.debug("Not dispatching %s to '%s' because it was just "
                               "loaded (%r).", event, module_name,
                               self.loaded_on_this_event)
                    continue
                module = self.loaded_modules[module_name]
                if module.handle_event(event, client, args):
                    return True
        finally:
            self.loaded_on_this_event = old_loaded
250693
def available_events
      state = current_state
      ret = {}
      while(state) do
        ret = state.class.specification.events.merge(ret)
        state = state.parent_state
      end
      ret
    end
171422
def event(from_states=None, to_state=None):
    
    from_states_tuple = (from_states, ) if isinstance(from_states, State) else tuple(from_states or [])
    if not len(from_states_tuple) >= 1:
        raise ValueError()
    if not all(isinstance(state, State) for state in from_states_tuple):
        raise TypeError()
    if not isinstance(to_state, State):
        raise TypeError()

    def wrapper(wrapped):

        @functools.wraps(wrapped)
        def transition(instance, *a, **kw):
            if instance.current_state not in from_states_tuple:
                raise InvalidStateTransition()
            try:
                result = wrapped(instance, *a, **kw)
            except Exception as error:
                error_handlers = getattr(instance, '___pystatemachine_transition_failure_handlers', [])
                for error_handler in error_handlers:
                    error_handler(instance, wrapped, instance.current_state, to_state, error)
                if not error_handlers:
                    raise error
            else:
                StateInfo.set_current_state(instance, to_state)
                return result

        return transition

    return wrapper
976207
def action_signal_triggered(self, model, prop_name, info):
        """"""
        # print("ACTION_signal_triggered state machine: ", model, prop_name, info)
        self.state_machine.marked_dirty = True
        msg = info.arg
        if model is not self and msg.action.startswith('sm_notification_'):  # Signal was caused by the root state
            # Emit state_action_signal to inform observing controllers about changes made to the state within the
            # state machine
            # print("DONE1 S", self.state_machine.state_machine_id, msg, model)
            # -> removes mark of "sm_notification_"-prepend to mark root-state msg forwarded to state machine label
            msg = msg._replace(action=msg.action.replace('sm_notification_', '', 1))
            self.state_action_signal.emit(msg)
            # print("FINISH DONE1 S", self.state_machine.state_machine_id, msg)
        else:
            # print("DONE2 S", self.state_machine.state_machine_id, msg)
            pass
599337
function listener (event, done) {
  return function onevent (arg1) {
    var args = new Array(arguments.length)
    var ee = this
    var err = event === 'error'
      ? arg1
      : null

    // copy args to prevent arguments escaping scope
    for (var i = 0; i < args.length; i++) {
      args[i] = arguments[i]
    }

    done(err, ee, event, args)
  }
}
651911
function callAllEventHandlers(...fns) {
  return (event, ...args) =>
    fns.some(fn => {
      if (fn) {
        fn(event, ...args)
      }
      return (
        event.preventDownshiftDefault ||
        (event.hasOwnProperty('nativeEvent') &&
          event.nativeEvent.preventDownshiftDefault)
      )
    })
}
479146
def _trigger(self, event_name, *args, **kwargs):
        
        self.log('event: %s' % event_name, *args)
        for f in self._events[event_name]:
            f(*args, **kwargs)
670578
def set_event_handler(self, event, handler):
        """"""
        # QUESTION: Should we raise an exception if `event` is not in some
        # known event-type list?

        self._prepare_persistence_engine()

        callbacks = self._options.get('callbacks', {})
        callbacks[event] = handler
        self._options['callbacks'] = callbacks
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);
				}
			}
		}
	}
153625
public synchronized void signal(String name) throws UnknownTransitionException {
        //check that start state defined
        if (start == null) {
            throw new IllegalStateException("The start sate is not defined");
        }

        //check that end state defined
        if (end == null) {
            throw new IllegalStateException("The end sate is not defined");
        }

        //ignore any signals if fsm reaches end state
//        if (state == end) {
//            return;
//        }

        String old = state.getName();
        //switch to next state
        state = state.signal(name);
        if (logger != null) {
            logger.debug(String.format("current state=%s, signal=%s, transition to=%s", old, name, state.getName()));
        }
    }
814706
function _readyState(o, c) {
        if (o.c.readyState === 4) {
            if (c.timeout) {
                _clearTimeout(o.id);
            }

            w.setTimeout(
                function() {
                    _ioComplete(o, c);
                    _handleResponse(o, c);
                }, 0);
        }
    }
114400
function(rpc_method, fn) {
        rpc.on(rpc_method, _.partial(moduleEventWrap, rpc_method, fn));
    }
1135199
def trigger(event_name, *data, &block)
      trigger!(event_name, *data, &block)
    rescue InvalidStateError, TransitionError, CallbackError
      false
    end
657543
function globalEventHandler(event) {
    if (listeners[event.type]) {
      listeners[event.type].forEach(function(currentHandler) {
        currentHandler.call(this, event);
      }, this);
    }
  }
576686
def trigger_event(self, event, client, args, force_dispatch=False):
        """"""
        self.controller.process_event(event, client, args, force_dispatch=force_dispatch)