es5 expose once

This commit is contained in:
Brandon Miller 2017-08-23 03:34:09 -07:00
parent 73d5ab559f
commit 74669c4a6a
8 changed files with 75 additions and 20 deletions

1
es5.js
View file

@ -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$;

View file

@ -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',

View file

@ -1,4 +1,5 @@
const Events = new require('../../event-pubsub.js');
'use strict';
const Events = require('../../event-pubsub.js');
const events=new Events;

View file

@ -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',

View file

@ -1,3 +1,4 @@
'use strict';
const Events = require('../../event-pubsub.js');
class Book extends Events{

View file

@ -1,3 +1,4 @@
'use strict';
const Events = require('../../event-pubsub.js');
/************************************\

42
examples/node/once-es5.js Normal file
View 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-'
);

View file

@ -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