Last active
October 7, 2017 11:50
-
-
Save fgarcia/043c1afac5a5b6ef6edd4aed739a8cb0 to your computer and use it in GitHub Desktop.
Revisions
-
Francisco Garcia revised this gist
Oct 7, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ function test() { // // You might be tempted to just test your code with 'once'. This however has two problems: // 1. You will not notice unexpected extra calls // 2. The code subscribing is out of your test, and it must always listen bus.on('my-signal', () => { console.log(' Catch!') }) -
Francisco Garcia revised this gist
Oct 7, 2017 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,8 +14,12 @@ function reset_2() { } function reset_3() { // WARNING // this solves the test problem, but also breaks code which makes a copy of your bus. // // If you pass around instances of your bus, it is very likely you will break something // if you just replace it with a new one bus = new EventEmitter2() } -
Francisco Garcia revised this gist
Oct 7, 2017 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,11 @@ function test() { console.log('Start test') // reset_1() // WARNING // // You might be tempted to just test your code with 'once'. This however has two problems: // 1. You will not notice unexpected extra calls // 2. The code subscribing is out of your test, and it always must listen bus.on('my-signal', () => { console.log(' Catch!') }) -
Francisco Garcia created this gist
Oct 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ > node test.js Start test Catch! end Start test Catch! Catch! end Start test Catch! Catch! Catch! end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ const {EventEmitter2} = require('eventemitter2') let bus bus = new EventEmitter2() function reset_1() { // fail ! bus.offAny() } function reset_2() { bus._all = [] bus._events = {} } function reset_3() { // solves test problem, // but breaks code that made a copy of the previous 'bus' bus = new EventEmitter2() } function test() { console.log('Start test') // reset_1() bus.on('my-signal', () => { console.log(' Catch!') }) bus.emit('my-signal', 'hello') console.log('end') console.log() console.log() } test() test() test()