Skip to content

Commit

Permalink
feat(api): modified tao so the api is consistent across adding handle…
Browse files Browse the repository at this point in the history
…rs & setting ctx

affects: tao

both adding handlers and setting context are more permissive in by allowing
the shortened { t, a, o } OR { term, action, orient } can be used to add handlers or set context (via setCtx)

additionally,
renamed `setCtx` => `setAppCtx` - denotes the arg is an AppCtx
renamed `setContext` => `setCtx` - shortened as it will be called most often
default setting context behavior now silently ignores setting to a Wildcard context
- this can be overridden using the canSetWilcard option to the TAO constructor
- it is assumed only Concrete contexts should be set as Wildcard is for handling and makes no sense for setting
cleaned up a lot of code

added output.txt as output of running example.js to run diff against
(until unit tests are written)
  • Loading branch information
eudaimos committed Mar 29, 2018
1 parent 506adae commit 69d287b
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 200 deletions.
24 changes: 12 additions & 12 deletions packages/tao/src/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ TAO.addInterceptHandler({}, logger);
TAO.addAsyncHandler(
{
// Context
term: 'App',
action: 'Init',
orient: 'Portal'
t: 'App',
a: 'Init',
o: 'Portal'
}, // Handler
(tao, data) => {
console.log(`=>| AppCtx from async: ['${tao.t}', '${tao.a}', '${tao.o}']`);
Expand All @@ -43,9 +43,9 @@ function inlineHandler(tao, data) {

TAO.addInlineHandler(
{
term: 'App',
action: 'Init',
orient: 'Portal'
t: 'App',
a: 'Init',
o: 'Portal'
},
(tao, data) => {
inlineHandler(tao, data);
Expand All @@ -61,7 +61,7 @@ console.log(`added Inline handler for 'App' 'Init' 'Portal'`);

TAO.addAsyncHandler(
{
orient: 'Portal'
o: 'Portal'
},
(tao, data) => {
console.log(
Expand All @@ -74,17 +74,17 @@ console.log(`added Async handler for '*' '*' 'Portal'`);

TAO.addInlineHandler(
{
term: 'App',
action: 'Enter',
orient: 'Portal'
t: 'App',
a: 'Enter',
o: 'Portal'
},
inlineHandler
);
console.log(`added Inline handler for 'App' 'Enter' 'Portal'`);

TAO.addInlineHandler(
{
orient: 'Portal'
o: 'Portal'
},
(tao, data) => {
console.log(
Expand All @@ -98,7 +98,7 @@ console.log(`added Inline handler for '*' '*' 'Portal'`);
console.log(
`=====><===== About to set context to 'App' 'Init' 'Portal' - let's see what happens =====><=====\n`
);
TAO.setContext(
TAO.setCtx(
{ t: 'App', a: 'Init', o: 'Portal' },
{
App: {
Expand Down
Loading

0 comments on commit 69d287b

Please sign in to comment.