Implementation of node-organic/Plasma v1.0.0.
Immediatelly triggers any reactions matching given c
chemical.
arguments
c
- Emitted chemical- as
String
equals to{ type: String, ... }
Chemical - as
Object
equals to Chemical
- as
returns
Promise<Array>
- returns a Promise which resolves to Array of Objects been the result of any reactions triggered by the emit.
throws
Array<Error>
- throws an Array of Error objects
notes
- Awaits any reactions in sequence based on their registration via
plasma.on
- Halts when a reaction throws
- Doesn't halt when a reaction returns error via callback signature
Does the same as plasma.emit
but triggers only the first matched
reaction.
returns
Promise
- returns a Promise which resolves to the result of the reaction matched by the emit pattern.
Does the same as plasma.emit
but also triggers any
reactions registered in the future using plasma.on
This method actually stored inmemory the c
chemical referenced within the plasma as storedChemical
.
returns
Promise<Array>
- returns a Promise which resolves to Array of Objects been the result of any reactions been triggered by the emit.
Does the same as plasma.emit
but also triggers any
reactions registered in the future using plasma.on
.
It overrides previously stored chemicals having the same chemical using c.type
returns
Promise<Array>
- returns a Promise which resolves to Array of Objects been the result of any reactions been triggered by the emit.
Checks synchronously for stored chemicals by given pattern
.
returns
Boolean
- returnstrue
when plasma contains a stored chemical matching givenpattern
Returns synchronously first found stored chemical by given pattern.
Returns synchronously all stored chemicals by given pattern.
Registers a function to be triggered when chemical emitted in plasma matches given pattern.
arguments
pattern
- matches emitted chemicals- as
String
matchingChemical.type
property - as
Object
matching one or many properties ofChemical
- as
c
-Object
Chemical matchingpattern
callback
- optional callback function used for feedbackcontext
- optional context to be used for calling the function
example
plasma.on({type: 'myChemical', kind: 'v1'}, async function (c) {
console.log(c) // {type: 'myChemical', kind: 'v1', ...}
await operation()
return result
})
let result = await plasma.emit({
type: 'myChemical',
kind: 'v1',
property: 'value'
})
The same as plasma.on(pattern, function reaction (c){})
but will trigger the function only once.
Registers a function to be triggered when all chemicals emitted in plasma have been matched.
arguments
p
- array- having elements
String
matchingChemical.type
property - having elements
Object
matching one or many properties ofChemical
- having elements
c
- arrayObject
Chemicals matchingp
array maintaining their index order
context
- optional context to be used for calling the function
The same as plasma.on([p1, p2], function(c1, c2){})
but will trigger the function only once.
Unregisters chemical reaction functions, the opposite of plasma.on
or plasma.once
.
arguments
pattern
- as
String
orArray
orObject
- needs function handler for unregister to succeed - as
Function
- finds all registered chemical reactions with that function handler and unregisters them.
- as
function
optional required only whenpattern
is String, Array or Object. This should be the exact function used forplasma.on
orplasma.once
context
optional used to scope removing of chemical reactions within context
Unregisters chemical reaction functions, the opposite of plasma.on
or plasma.once
.
arguments
function
this should be the exact function used forplasma.on
orplasma.once
context
optional used to scope removing of chemical reactions within context
Removes previously stored chemical via plasma.store
. It does removal by reference and won't throw exception if given chemical is not found in plasma's store.
Removes previously stored chemicals via plasma.store
. It does removal by chemical pattern
Method which will invoke function per any chemical been emitted or stored in plasma.
Stops invoking given function previously used for plasma.pipe
Current implementation of organic plasma interface has the following addon features designed for ease in daily development process.
Invoking either:
plasma.emit('ready')
plasma.emit({type: 'ready'})
triggers all the following:
plasma.on('ready', function(c){ c.type === 'ready' })
plasma.on({type: 'ready'}, function(c){ c.type === 'ready' })
plasma.on('c1', function reaction1 (c, callback) {
callback(c)
})
plasma.emit('c1', function callback (c) {
// c.type === 'c1'
})
plasma.on('c1', async function reaction1 (c) {
let result
return result
})
let result = await plasma.emit('c1')
console.log(result)
- override
plasma.utils.deepEqual(pattern, chemical)
var Class1 = function () {}
plasma.on(Class1, function (instance) {
})
var instance = new Class1()
plasma.emit(instance)
When emitting a chemical (via the .emit
method) which has no registered handlers (via the .on
/.once
methods) an Error will be thrown
- The missing handlers error chemical will not be thrown when storing chemicals.
- by default this feature is disabled unless
throwOnMissingHandler
value is set totrue
var instance = new Plasma({
throwOnMissingHandler: true
})
instance.emit("chemicalWithNoHandler") // throws Error