Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Events hash created when building object
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkin committed Oct 17, 2017
1 parent c669fcf commit b5d07dc
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
11 changes: 6 additions & 5 deletions dist/sequential-event.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sequential-event.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/sequential-event.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/SequentialEvent.html
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2017-10-17T17:14:16+02:00
on 2017-10-17T17:35:29+02:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/classes.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2017-10-17T17:14:16+02:00
on 2017-10-17T17:35:29+02:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2017-10-17T17:14:16+02:00
on 2017-10-17T17:35:29+02:00

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/quicksearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="scripts/fulltext-search.js"></script>

<script type="text/x-docstrap-searchdb">
{"classes.list.html":{"id":"classes.list.html","title":"Classes","body":" Documentation Classes SequentialEvent Classes Classes SequentialEvent × Search results Close Documentation generated by JSDoc 3.5.5 on 2017-10-17T17:14:16+02:00 using the DocStrap template. "},"index.html":{"id":"index.html","title":"Index","body":" Documentation Classes SequentialEvent SequentialEvent.jsCode checks: Package infos: See the API documentation on github.io/SequentialEvent.js This library is a variation of standard event emitters. Handlers are executed sequentialy, and may return Promises if it executes asynchronous code. For usage in the browser, use the files in the dist directory Example usageconst SequentialEvent = require( 'sequential-event' ); function sampleTime( startTime ) { return new Date().getTime() - startTime; } const eventEmitter = new SequentialEvent(); // We create a new array with a new timer eventEmitter.on( 'retime', startTime =&gt; { return [ sampleTime( startTime ) ]; }); // We wait 100ms and we re-time eventEmitter.on( 'retime', ( startTime, timers ) =&gt; { // This operation is async, so we return a Promise that will be resolved with the timers array return new Promise(( resolve ) =&gt; { setTimeout(() =&gt; { timers.push( sampleTime( startTime )); return resolve( timers ); }, 100 ); }); }); // We re-take a sample immediatly eventEmitter.on( 'retime', ( startTime, timers ) =&gt; { // This operation is sync, so we can return our timers array directly timers.push( sampleTime( startTime )); return timers; }); eventEmitter // Emit our retime event with the current date .emit( 'retime', new Date().getTime()) // Log normaly if everything is OK, or log with error .then( timers =&gt; console.log( timers )) .catch( err =&gt; console.error( err ));Sample output [ 1, 109, 109 ] You can see that each on handlers are executed sequentially, after the end of the previous handler. APIThe API is based on Node's EventEmitter. This package provides a re-implementation of the emit method. See the Node EventEmitter for methods documentation CompatibilityThis package can run on Node &gt;= 6.0.0 Most modern browsers Index sequential-event.js File defining the SequentialEvent class Author: Gerkin × Search results Close Documentation generated by JSDoc 3.5.5 on 2017-10-17T17:14:16+02:00 using the DocStrap template. "},"SequentialEvent.html":{"id":"SequentialEvent.html","title":"Class: SequentialEvent","body":" Documentation Classes SequentialEvent Class: SequentialEvent SequentialEvent Event emitter that guarantees sequential execution of handlers. Each handler may return a Promise. new SequentialEvent() Constructs a new SequentialEvent. See: Node EventEmitter. Methods &lt;private, static&gt; emitHandler(handler, object [, args]) Handle execution of a single handler. Parameters: Name Type Argument Description handler function Function to execute. It may return a Promise. object EventEmitter Object to call event on. args Array.&lt;Any&gt; &lt;optional&gt; Arguments to pass to each called function. Author: Gerkin Returns: Promise resolved once this function is done. Type Promise &lt;private, static&gt; emitHandlers(handlers, object [, args]) Handle execution of all handlers in sequence. Parameters: Name Type Argument Description handlers function | Array.&lt;function()&gt; Function(s) to execute. Each function may return a Promise. object EventEmitter Objecto call event on. args Array.&lt;Any&gt; &lt;optional&gt; Arguments to pass to each called function. Author: Gerkin Returns: Promise resolved once each function is executed. Type Promise emit(type [, args]) Triggers each corresponding handlers in sequence. Parameters: Name Type Argument Description type Any Name of the event to sequential-event. args Array.&lt;Any&gt; &lt;optional&gt; &lt;repeatable&gt; Parameters to pass to handlers. Author: Gerkin Returns: Returns a Promise resolved when then chain is done. Type Promise off( [events] [, callback]) Remove one or many or all event handlers. Parameters: Name Type Argument Description events string | Object &lt;optional&gt; Event name or hash of events. callback function &lt;optional&gt; If provided an event name with events, function to associate with the event. Returns: this. Type SequentialEvent on(events [, callback]) Add one or many event handlers. Parameters: Name Type Argument Description events string | Object Event name or hash of events. callback function &lt;optional&gt; If provided an event name with events, function to associate with the event. Returns: this. Type SequentialEvent once(events [, callback]) Add one or many event handlers that will be called only once. Parameters: Name Type Argument Description events string | Object Event name or hash of events. callback function &lt;optional&gt; If provided an event name with events, function to associate with the event. Returns: this. Type SequentialEvent &lt;inner&gt; getNextPromise(prevResolve) Generate next promise for sequence. Parameters: Name Type Description prevResolve Any Event chain resolved value. Author: Gerkin Returns: This function does not return anything. Type undefined × Search results Close Documentation generated by JSDoc 3.5.5 on 2017-10-17T17:14:16+02:00 using the DocStrap template. "}}
{"classes.list.html":{"id":"classes.list.html","title":"Classes","body":" Documentation Classes SequentialEvent Classes Classes SequentialEvent × Search results Close Documentation generated by JSDoc 3.5.5 on 2017-10-17T17:35:29+02:00 using the DocStrap template. "},"index.html":{"id":"index.html","title":"Index","body":" Documentation Classes SequentialEvent SequentialEvent.jsCode checks: Package infos: See the API documentation on github.io/SequentialEvent.js This library is a variation of standard event emitters. Handlers are executed sequentialy, and may return Promises if it executes asynchronous code. For usage in the browser, use the files in the dist directory Example usageconst SequentialEvent = require( 'sequential-event' ); function sampleTime( startTime ) { return new Date().getTime() - startTime; } const eventEmitter = new SequentialEvent(); // We create a new array with a new timer eventEmitter.on( 'retime', startTime =&gt; { return [ sampleTime( startTime ) ]; }); // We wait 100ms and we re-time eventEmitter.on( 'retime', ( startTime, timers ) =&gt; { // This operation is async, so we return a Promise that will be resolved with the timers array return new Promise(( resolve ) =&gt; { setTimeout(() =&gt; { timers.push( sampleTime( startTime )); return resolve( timers ); }, 100 ); }); }); // We re-take a sample immediatly eventEmitter.on( 'retime', ( startTime, timers ) =&gt; { // This operation is sync, so we can return our timers array directly timers.push( sampleTime( startTime )); return timers; }); eventEmitter // Emit our retime event with the current date .emit( 'retime', new Date().getTime()) // Log normaly if everything is OK, or log with error .then( timers =&gt; console.log( timers )) .catch( err =&gt; console.error( err ));Sample output [ 1, 109, 109 ] You can see that each on handlers are executed sequentially, after the end of the previous handler. APIThe API is based on Node's EventEmitter. This package provides a re-implementation of the emit method. See the Node EventEmitter for methods documentation CompatibilityThis package can run on Node &gt;= 6.0.0 Most modern browsers Index sequential-event.js File defining the SequentialEvent class Author: Gerkin × Search results Close Documentation generated by JSDoc 3.5.5 on 2017-10-17T17:35:29+02:00 using the DocStrap template. "},"SequentialEvent.html":{"id":"SequentialEvent.html","title":"Class: SequentialEvent","body":" Documentation Classes SequentialEvent Class: SequentialEvent SequentialEvent Event emitter that guarantees sequential execution of handlers. Each handler may return a Promise. new SequentialEvent() Constructs a new SequentialEvent. See: Node EventEmitter. Methods &lt;private, static&gt; emitHandler(handler, object [, args]) Handle execution of a single handler. Parameters: Name Type Argument Description handler function Function to execute. It may return a Promise. object EventEmitter Object to call event on. args Array.&lt;Any&gt; &lt;optional&gt; Arguments to pass to each called function. Author: Gerkin Returns: Promise resolved once this function is done. Type Promise &lt;private, static&gt; emitHandlers(handlers, object [, args]) Handle execution of all handlers in sequence. Parameters: Name Type Argument Description handlers function | Array.&lt;function()&gt; Function(s) to execute. Each function may return a Promise. object EventEmitter Objecto call event on. args Array.&lt;Any&gt; &lt;optional&gt; Arguments to pass to each called function. Author: Gerkin Returns: Promise resolved once each function is executed. Type Promise emit(type [, args]) Triggers each corresponding handlers in sequence. Parameters: Name Type Argument Description type Any Name of the event to sequential-event. args Array.&lt;Any&gt; &lt;optional&gt; &lt;repeatable&gt; Parameters to pass to handlers. Author: Gerkin Returns: Returns a Promise resolved when then chain is done. Type Promise off( [events] [, callback]) Remove one or many or all event handlers. Parameters: Name Type Argument Description events string | Object &lt;optional&gt; Event name or hash of events. callback function &lt;optional&gt; If provided an event name with events, function to associate with the event. Returns: this. Type SequentialEvent on(events [, callback]) Add one or many event handlers. Parameters: Name Type Argument Description events string | Object Event name or hash of events. callback function &lt;optional&gt; If provided an event name with events, function to associate with the event. Returns: this. Type SequentialEvent once(events [, callback]) Add one or many event handlers that will be called only once. Parameters: Name Type Argument Description events string | Object Event name or hash of events. callback function &lt;optional&gt; If provided an event name with events, function to associate with the event. Returns: this. Type SequentialEvent &lt;inner&gt; getNextPromise(prevResolve) Generate next promise for sequence. Parameters: Name Type Description prevResolve Any Event chain resolved value. Author: Gerkin Returns: This function does not return anything. Type undefined × Search results Close Documentation generated by JSDoc 3.5.5 on 2017-10-17T17:35:29+02:00 using the DocStrap template. "}}
</script>

<script type="text/javascript">
Expand Down
Loading

0 comments on commit b5d07dc

Please sign in to comment.