diva
still in development mode
Overview
This module is a base to write node modules with clear, concise, and expressive code. It provides a base class, methods, and patterns for creating concurrent, actor-based javascript.
Basically, the goal is to allow expressive, simple scripting like this:
var jimmy = ;var dana = ; ;; jimmy
More generally, expanding this module with other popular modules like request can create simple and expressive client side modules for interacting with apis.
client
The module depends on RSVP, but any promise library including native ES6 Promises should work.
## Installation
This module is installed via npm:
$ npm install diva
## API
Initialization
Use diva() to add the Diva skeleton to the class:
var diva = ; var { thisname = 'Name';} ;
that.queue( fn )
Description
Creates a function to create a promise in the internal queue. Use with prototypes to create chainable waterfall promises.
that
Promise
Description
Expose the rsvp Promise object
var Promise = Promise
run
Description
Run the current queue, passing in a value to the first method in the chain.
stop
Description
Stop running the queue.
empty
Description
Empty the current queue.
before, after
Description
Add a promise before or after every time a particular method is called in the chain
set
Description
Set the waterfall value as a property of the diva object (for later reference.) If a value is spacified, then that value will be set and passed down the waterfall.
### get
Description
Get a property of the diva object and send it down the waterfall
### remove
Description
Get and remove a property of the diva object and send it down the waterfall
### display
Description
Display the current waterfall value or a string. The current waterfall value passes through in either case.
display<string>
### pause
Description
Pause the chain for a certain amount of time
### change
Description
Change the waterfall value
send
Description
Send the current value (or a specified message) to another diva chain that will receive the message with onReceipt (it does not have to be a diva object)
Description
Mail a current value to another diva chain that will receive the message and put it in its mailbox
onReceive( fn(msg) { })
Description
Receive the value from a sender. Execute immediately, or call diva methods from the callback and run to run synchronously after the current queue.
isRunning()
Description
Returns true if the diva object is running a queue
retrieve()
Description
Pull the bottom (oldest) x values out of the mailbox
draw()
Description
Pull the top (recent) x values out of the mailbox
Example Usage
var request =diva =Promise = Promisefs =
Create any type of "object"
var { }
Add the diva prototypes to the object type.
Person = ;
Create methods with a specific signature:
var that = this; return that;
Chain methods together and send messages to other diva objects (or any message handler)
johnname = 'john'maryname = 'mary' var end = { console } john display display"John: I'm back!!!" display'Will not show up' mary display display'**Mary is twiddling her thumbs**' display'Mary: John is not back yet' display'Mary: Let me ask where he is.' display"Mary: Why don't I check the mail..." display display'((Sleep))' display'Will show up' console