diff --git a/es5.js b/es5.js index 033c9d4..7faf8b7 100644 --- a/es5.js +++ b/es5.js @@ -4,6 +4,7 @@ function EventPubSub() { this._events_={}; this.publish=this.trigger=this.emit=emit; this.subscribe=this.on=on; + this.once=once; this.unSubscribe=this.off=off; this.emit$=emit$; diff --git a/examples/node/basic-es5.js b/examples/node/basic-es5.js index 167af85..131f7e2 100644 --- a/examples/node/basic-es5.js +++ b/examples/node/basic-es5.js @@ -1,5 +1,9 @@ -const Events = require('../../es5.js'); -const events = new Events; +'use strict'; +// requireing 'event-pubsub' module will auto detect ES6/ES5 support +// so we will force it here incase you support ES6 +// for example sake +var ForceES5 = require('../../es5.js'); +var events = new ForceES5; events.on( 'hello', diff --git a/examples/node/basic.js b/examples/node/basic.js index 98fa05e..1a2f82a 100644 --- a/examples/node/basic.js +++ b/examples/node/basic.js @@ -1,4 +1,5 @@ -const Events = new require('../../event-pubsub.js'); +'use strict'; +const Events = require('../../event-pubsub.js'); const events=new Events; diff --git a/examples/node/extending-es5.js b/examples/node/extending-es5.js index 032ed46..e602cb8 100644 --- a/examples/node/extending-es5.js +++ b/examples/node/extending-es5.js @@ -1,4 +1,8 @@ -const Events = require('../../es5.js'); +'use strict'; +// requireing 'event-pubsub' module will auto detect ES6/ES5 support +// so we will force it here incase you support ES6 +// for example sake +var Events = require('../../es5.js'); function Book(){ //extend happens below @@ -24,7 +28,7 @@ function Book(){ } function erase(count){ - const words=this.words.splice( + var words=this.words.splice( -count ); this.trigger( @@ -43,7 +47,7 @@ function Book(){ return this; }; -const book=new Book; +var book=new Book; book.on( 'added', diff --git a/examples/node/extending.js b/examples/node/extending.js index 3b8a436..2b23a69 100644 --- a/examples/node/extending.js +++ b/examples/node/extending.js @@ -1,3 +1,4 @@ +'use strict'; const Events = require('../../event-pubsub.js'); class Book extends Events{ diff --git a/examples/node/multiple.js b/examples/node/multiple.js index ca123c4..8c798bc 100644 --- a/examples/node/multiple.js +++ b/examples/node/multiple.js @@ -1,3 +1,4 @@ +'use strict'; const Events = require('../../event-pubsub.js'); /************************************\ diff --git a/examples/node/once-es5.js b/examples/node/once-es5.js new file mode 100644 index 0000000..b6aacef --- /dev/null +++ b/examples/node/once-es5.js @@ -0,0 +1,42 @@ +'use strict'; +// requireing 'event-pubsub' module will auto detect ES6/ES5 support +// so we will force it here incase you support ES6 +// for example sake +var Events = require('../../es5.js'); + +var events=new Events; + + +/**********************************\ + * + * Demonstrate once + * + * ********************************/ +events.once( + 'test.once', + (data)=>{ + console.log(`got data ${data} from .once`) + } +); + +events.on( + 'test.once', + (data)=>{ + console.log(`got data ${data} from .on with true`) + }, + true +); + +/************************************\ + * emit events for testing + * **********************************/ + +events.emit( + 'test.once', + '-5 TESTING-' +); + +events.emit( + 'test.once', + '-5 NEVER SEE THIS-' +); diff --git a/examples/node/once.js b/examples/node/once.js index 4a60b96..1a82d6a 100644 --- a/examples/node/once.js +++ b/examples/node/once.js @@ -1,4 +1,5 @@ -const Events = new require('../../event-pubsub.js'); +'use strict'; +const Events = require('../../event-pubsub.js'); const events=new Events; @@ -7,20 +8,20 @@ const events=new Events; * Demonstrate once * * ********************************/ - events.once( - 'test.once', - (data)=>{ - console.log(`got data ${data} from .once`) - } - ); +events.once( + 'test.once', + (data)=>{ + console.log(`got data ${data} from .once`) + } +); - events.on( - 'test.once', - (data)=>{ - console.log(`got data ${data} from .on with true`) - }, - true - ); +events.on( + 'test.once', + (data)=>{ + console.log(`got data ${data} from .on with true`) + }, + true +); /************************************\ * emit events for testing