Hookers: defineStates, defineWorkflow

by andypotanin

JavaScript

Object.defineStates = function() {}
Object.defineWorkflow = function() {}

// Create a Constructor
function Hooker( name, data, meta ) {
    this.name = name || 'RandomHooker';
    this.data = data || {};
    this.meta = meta || {};  
    return this;
}

// Create our first hooker. 
// Our States and Workflows are going to operate within the context of Julia object.
var Julia = new Hooker( 'Julia', { 
    class: 10,
    hair: 'brown' 
});

// These attributes should change for the purpose of our tests, rotating between different values at certain time intervals to simulate state changes.
// The age should increment. When it gets to "50" Julia will be considered too old for work. 
Julia.mood = 'good';
Julia.hungry = false;
Julia.age = 33;

// Identify the types of states that Julia will have that we want to be aware of.
// The JSON Schema applies to the entire Julia object and must validate for the state tocome active.
Object.defineStates( Julia, {
    old: {
        age: {
            description: 'Julia is too old to be a hooker. (We assume her age changed via some sort of timer)',
            required: true,
            type: "string",
            maximum: 50
        }
    },
    busy: {
        status: {
            description: 'Julia is unavailable for work. We mark her as being busy when the Julia.busy property matches one of the enum values.',
            required: true,
            type: "string",
            enum: [ "sleeping", "on_break", "with_client" ], 
        }
    }
});

// Following the JS Object pattern states can be added individually.
// This state is triggered when Julia is horny, which appens when she is not hungry and her mood is either "good", "awesome" or "excellent";
Object.defineState( Julia, 'horny', {
    horny: {
        mood: {
            description: 'The value of "mood" property in Julia.data must be one of the following.',
            required: true,
            type: 'string',
            enum: [ 'good', 'awesome', 'excellent'...