Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event based behavior(actions) framework #26

Open
minjing opened this issue Aug 3, 2016 · 3 comments
Open

Event based behavior(actions) framework #26

minjing opened this issue Aug 3, 2016 · 3 comments
Assignees
Milestone

Comments

@minjing
Copy link
Owner

minjing commented Aug 3, 2016

No description provided.

@minjing minjing self-assigned this Aug 3, 2016
@minjing minjing changed the title Event based behavior(actions) execution Event based behavior(actions) framework Sep 19, 2016
@minjing
Copy link
Owner Author

minjing commented Sep 19, 2016

Terminology

  • Event is a generic data object
  • Event source is able to publish event
  • Action is a minimal data handler unit
  • Behavior is constructed by one or more Actions
  • An event can be handled by specified Behavior

Key Points

  • Define event source (data source) in the java code
  • Define action in the java code
  • Define behavior in the script
  • Combine event source and behavior in the script
  • The event and sub-event should be tracable.

Defintion:

when([EVENT_NAME]).then(function(event) {
      [EXECUTION_BODY]
}

The execution body support below:

  • Sequence execution
  • Branch statement execution
  • loop statement execution

@minjing
Copy link
Owner Author

minjing commented Oct 17, 2016

One .js file define one Responsible, one Responsible can define one or more event based behavior functions.

The .js file structure should be like below:

{
    "name": "xxx",  // The name of Responsible
    "behaviors": [{
        "event": "xxx",  // The event name
        "behavior" = function() {...}  // The behavior codes
    }, {
        ...
    }]
}

The behavior is a javascript function, you can invoke any action and non-event-based behavior:

{
    "event": ${event_name},
    "behavior": function(event) {
        createPipe().then("xxx").then("xxx");
    }
}

The above "xxx" is action name or behavior name, if action name and behavior name is duplicated, you can add prefix: action:xxx or behavior:xxx.

Create behavior with branch:

function(event) {
    var result = createPipe().with(event).then("xxx").execute();
    if (result.t === 'test') {
        createPipe().with(result).then("xxx").execute();
    } else {
        createPipe().with("xxx").then("xxx");
    }
}

We also can using for/while in the function:

function(event) {
    var result = createPipe().with(event).then("xxx").execute();
    for (var i = 0; i < result.count; i++) {
        createPipe().with(i).then("xxx").execute();
    }
}

@minjing
Copy link
Owner Author

minjing commented Oct 27, 2016

There are two phases to deliver the feature:

  • Phase 1, implement event framework, implement define simple event based behavior by program way.
  • Phase 2, implement define complex event based behavior by javascript or program way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant