File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ const subscribe = (type, callback) => {
1212
1313 subscriptions [ type ] [ id ] = callback ;
1414
15+ let last = map . get ( type ) ;
16+
17+ if ( last ) {
18+ callback ( last ) ;
19+ }
20+
1521 return {
1622 unsubscribe : ( ) => {
1723 delete subscriptions [ type ] [ id ] ;
Original file line number Diff line number Diff line change @@ -14,6 +14,15 @@ describe("react-event", () => {
1414 publish ( "TEST_EVENT" , { number : 10 , string : "blue" } ) ;
1515 } ) ;
1616
17+ it ( "publishes and subscribes events" , ( done ) => {
18+ publish ( "TEST_EVENT" , { number : 10 , string : "blue" } ) ;
19+
20+ subscribe ( "TEST_EVENT" , ( result ) => {
21+ expect ( result ) . toMatchObject ( { number : 10 , string : "blue" } ) ;
22+ done ( ) ;
23+ } ) ;
24+ } ) ;
25+
1726 it ( "notifies all subscribers of an event" , ( done ) => {
1827 let receivedByFirstSubscriber = false ;
1928 let receivedBySecondSubscriber = false ;
You can’t perform that action at this time.
0 commit comments