File tree Expand file tree Collapse file tree 3 files changed +12
-13
lines changed Expand file tree Collapse file tree 3 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -9,28 +9,16 @@ class MonadIODef {
9
9
return fn ( self . effect ( ) ) ;
10
10
} ) ;
11
11
}
12
- bind ( fn ) {
13
- return this . then ( fn ) ;
14
- }
15
- map ( fn ) {
16
- return this . then ( fn ) ;
17
- }
18
12
flatMap ( fn ) {
19
13
return this . then ( ( result ) => fn ( result ) . effect ( ) ) ;
20
14
}
21
15
of ( ref ) {
22
16
var m = new MonadIODef ( ( ) => ref ) ;
23
17
return m ;
24
18
}
25
- just ( ref ) {
26
- return this . of ( ref ) ;
27
- }
28
19
ap ( fnM ) {
29
20
return fnM . chain ( f => this . map ( f ) ) ;
30
21
}
31
- chain ( fn ) {
32
- return this . flatMap ( fn ) ;
33
- }
34
22
35
23
subscribe ( fn , asynchronized ) {
36
24
if ( asynchronized ) {
@@ -41,6 +29,10 @@ class MonadIODef {
41
29
return fn ;
42
30
}
43
31
}
32
+ MonadIODef . prototype . just = MonadIODef . prototype . of
33
+ MonadIODef . prototype . chain = MonadIODef . prototype . flatMap
34
+ MonadIODef . prototype . bind = MonadIODef . prototype . then
35
+ MonadIODef . prototype . map = MonadIODef . prototype . then
44
36
45
37
var MonadIO = new MonadIODef ( { } ) ;
46
38
MonadIO . fromPromise = function ( p ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ class Publisher {
23
23
unsubscribe ( fn ) {
24
24
this . subscribers = this . subscribers . filter ( ( item ) => item !== fn ) ;
25
25
}
26
+ clear ( ) {
27
+ this . subscribers = [ ]
28
+ }
26
29
publish ( result , asynchronized ) {
27
30
this . subscribers . forEach ( ( fn ) => asynchronized ? Promise . resolve ( result ) . then ( fn ) : fn ( result ) ) ;
28
31
}
Original file line number Diff line number Diff line change @@ -7,8 +7,12 @@ describe('Publisher', function () {
7
7
8
8
v = 0 ;
9
9
p . subscribe ( ( i ) => v = i ) ;
10
- p . publish ( 1 ) ;
11
10
11
+ p . publish ( 1 ) ;
12
+ v . should . equal ( 1 )
13
+ // Clear
14
+ p . clear ( )
15
+ p . publish ( 2 ) ;
12
16
v . should . equal ( 1 )
13
17
} ) ;
14
18
it ( 'async' , function ( done ) {
You can’t perform that action at this time.
0 commit comments