install
npm install --save gyre
Usage
index.html
hello order! View Name View name, and gender View all
script.shell.js
Passing a generator function to $$.shell
creates a co-routine. This example uses the then-fs module. It also uses es2015 template strings which are available in electron at least -- while there are various levels of support for browsers.
var fs = { return fs; }; var $$ = ; var fullName = $$; var nameHTML = $$; nameHTML; var nameWithGender = $$;var all = $$; all; nameWithGender;all; document; document;document;
$$.shell(generator, function, asyncFunction) -> shell Object
$$.shell
is a factory. These are the things you can pass to it.
- Generator
- Promise returning function
- async/await type functions
Once you've created an object with it you can now access some methods.
shell.include(shell, ...) -> this
include is a special function for adding parameters to the calling object.
For instance:
var fullName = $$; var nameHTML = $$; nameHTML;
Very Important: In that last example the return value of fullName
becomes the argument value of the parameter name
in nameHTML
. With co-routines this mechanism of extending arguments is a very important ability of gyre shells. It's what allows the composition of shells into a much larger series of operations.
shell.erase() -> this
is the opposite of include. It erases all arguments.
Use shell.exec(object) -> this
to run the shell co-routine.
shell.on(string, function) -> this
allows you to set at least one event named exec
.
shell.destroy() -> undefined
The nuclear option. The destroyed shell as well as it's child arguments set through include are all rendered ineffective permanently by destroy
.
A promise will still be returned from exec
after destroy
is called, but it will resolve to an undefined value for for the rest of the programs life. Reassign the variable or something after a destroy
call.
shell events
These are the events that shells emit.
- exec
- destroy
co-routines
Keep in mind that unlike the co library you can only yield promises to perform asynchronous operations. Any other value is treated as a synchronous value.
As an alternative creation mechanism you can use async/await.
var myShell = $$;myShell;
$$.state()
//Create a new state manager.var states = $$;
Use states.add(String|RegExp, shell)
to use states.
The shell object returned by gyre has the exec
, and destroy
methods so it is compatible with carefree-states.
Visit the carefree-states module to learn more about states.
About
gyre uses composition to create functions that have growing arity. I call these functions of growing arity shells due to their layered appearance.
For you functional programming aficionados out there this could be considered the opposite of partial application. Though in the end it comes full circle with the exec function to a true partial.
What's it for?
Wow! I agonized over what to call these things for a couple days. You'll think of something.
I can at least tell you I made gyre to use in the electron framework. In my opinion this is where it will shine as a template organizer, and model manager.
Happy coding!