mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-05 09:31:42 -05:00
es5 expose once
This commit is contained in:
parent
73d5ab559f
commit
74669c4a6a
8 changed files with 75 additions and 20 deletions
1
es5.js
1
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$;
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const Events = new require('../../event-pubsub.js');
|
||||
'use strict';
|
||||
const Events = require('../../event-pubsub.js');
|
||||
|
||||
const events=new Events;
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
const Events = require('../../event-pubsub.js');
|
||||
|
||||
class Book extends Events{
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
const Events = require('../../event-pubsub.js');
|
||||
|
||||
/************************************\
|
||||
|
|
42
examples/node/once-es5.js
Normal file
42
examples/node/once-es5.js
Normal file
|
@ -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-'
|
||||
);
|
|
@ -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(
|
||||
events.once(
|
||||
'test.once',
|
||||
(data)=>{
|
||||
console.log(`got data ${data} from .once`)
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
events.on(
|
||||
events.on(
|
||||
'test.once',
|
||||
(data)=>{
|
||||
console.log(`got data ${data} from .on with true`)
|
||||
},
|
||||
true
|
||||
);
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* emit events for testing
|
||||
|
|
Loading…
Add table
Reference in a new issue