const StateMachine = function(states, transitions, initialState = null) {
	this.state = initialState;
	this.states = states;

	this.transitions =transitions;

	this.transitions.forEach((t) => {
		// Create transitions closures
		this[t.trigger] = () => {
			console.log('executing trigger:', t.trigger);
			if(t.source !== this.state ) {
				console.error(`invalid transition: ${this.state} -> ${t.target}`);
				return false;
			}
			console.log(`${this.state} -> ${t.target}`);
			this.state = t.target;
			return true;
		}
	});

	this.initialize = (initialState) => {
		if(this.state) {
			console.error('Machine is already initialized to:', this.state);
			return false;
		}

		if(this.states.includes(initialState)) {
			this.state=initialState;
		}
		else {
			console.error(`error initializing state maching, state:${initialState} is not part of ${this.states}`);
			return false;
		}
		return true;
	}

	this.getState = () => this.state;

	return this;
};

module.exports = StateMachine;

@@ -98,64 +98,193 @@
 ate;
-%0A%09this.states = states;%0A%0A%09this.transitions =transitions;
+  // TODO: validate it's part of states%5B%5D%0A%09this.states = states;  // TODO: validate structure and uniqueness%0A%0A%09this.transitions =transitions;  // TODO: validate structure and uniqueness
 %0A%0A%09t
@@ -904,17 +904,17 @@
 .error(%60
-e
+E
 rror ini
@@ -939,17 +939,18 @@
 chin
-g,
+e:
  state:
+ 
 $%7Bin
@@ -1070,16 +1070,307 @@
 state;%0A%0A
+%09this.addTransition = (transition) =%3E this.transitions.push(transition); // TODO: validate structure and uniqueness%0A%0A%09this.removeTransition = (trigger) =%3E %7B%0A%09%09const transitionIndex = this.transitions.findIndex((t) =%3E t.trigger === trigger);%0A%09%09this.transitions.slice(transitionIndex, 1);%0A%09%7D%0A%0A
 %09return 

implement add and remove transitions functions