Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
common
Commits
fd01e2ae
Commit
fd01e2ae
authored
Nov 21, 2018
by
Vladislav Lagunoff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[eff] Исправлена ошибка в обработке Chain
parent
1fdae3a5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
17 deletions
+26
-17
eff/index.ts
+26
-17
No files found.
eff/index.ts
View file @
fd01e2ae
...
...
@@ -17,6 +17,8 @@ export type Eff<Error, Success> =
|
Apply
<
Error
,
Success
>
// { args: Eff<unknown>[], proj(...args): Either<Error, Success> }
|
Chain
<
Error
,
Success
>
// { first: Eff<unknown>, andThen(x: unknown): Eff<Error, Success> }
|
HasEffect
<
Error
,
Success
>
// { toEffect(): Eff<Error, Success> }
;
export
type
AnyEff
=
Eff
<
any
,
any
>
;
// Instance methods for `Eff`
...
...
@@ -140,7 +142,7 @@ export function ap(): Eff<unknown, unknown> {
}
export
function
record
<
R
extends
Record
<
string
,
Eff
<
any
,
any
>
>>
(
rec
:
R
):
Eff
<
{
[
K
in
keyof
R
]:
R
[
K
][
'_Error'
]
}[
keyof
R
],
{
[
K
in
keyof
R
]:
R
[
K
][
'_Success'
]
}
>
{
export
function
record
<
R
extends
Record
<
string
,
AnyEff
>>
(
rec
:
R
):
Eff
<
{
[
K
in
keyof
R
]:
R
[
K
][
'_Error'
]
}[
keyof
R
],
{
[
K
in
keyof
R
]:
R
[
K
][
'_Success'
]
}
>
{
const
keys
=
Object
.
keys
(
rec
);
return
ap
.
apply
(
undefined
,
[...
keys
.
map
(
k
=>
rec
[
k
]),
(...
values
)
=>
values
.
reduce
((
acc
,
v
,
idx
)
=>
(
acc
[
keys
[
idx
]]
=
v
,
acc
),
{})]);
}
...
...
@@ -240,23 +242,27 @@ export function go<Error, Success>(effect: Eff<Error, Success>, onNext: (x: Eith
}
if
(
effect
instanceof
Chain
)
{
const
subscriptions
:
Array
<
Function
|
null
>
=
[];
subscriptions
.
push
(
go
(
effect
.
first
,
result
=>
{
const
idx
=
subscriptions
.
length
;
subscriptions
.
push
(
go
(
effect
.
andThen
(
result
),
onNext
,
()
=>
{
subscriptions
[
idx
]
=
null
;
for
(
const
unsub
of
subscriptions
)
if
(
unsub
!==
null
)
return
;
onComplete
();
}));
},
()
=>
{
subscriptions
[
0
]
=
null
;
for
(
const
unsub
of
subscriptions
)
if
(
unsub
!==
null
)
return
;
onComplete
();
}));
const
cancellers
=
new
Map
<
AnyEff
,
Canceller
>
();
const
handleEffect
=
(
e
:
AnyEff
)
=>
{
const
_onNext
=
result
=>
{
if
(
e
===
effect
.
first
)
handleEffect
(
effect
.
andThen
(
result
));
else
onNext
(
result
);
};
const
_onComplete
=
()
=>
{
if
(
!
cancellers
.
has
(
e
))
completedImmediately
=
true
;
cancellers
.
delete
(
e
);
if
(
cancellers
.
size
===
0
)
onComplete
();
};
let
completedImmediately
=
false
;
return
()
=>
subscriptions
.
forEach
(
funOrNull
=>
funOrNull
?
funOrNull
()
:
void
0
);
const
canceller
=
go
(
e
,
_onNext
,
_onComplete
);
if
(
!
completedImmediately
)
cancellers
.
set
(
e
,
canceller
);
};
handleEffect
(
effect
.
first
);
if
(
cancellers
.
size
===
0
)
return
noopFunc
;
return
()
=>
cancellers
.
forEach
(
canceller
=>
canceller
());
}
if
(
effect
instanceof
Apply
)
{
...
...
@@ -355,6 +361,9 @@ export abstract class HasEffect<Error, Success> extends EffBase<Error, Success>
export
const
noop
:
Cmd
<
never
>
=
new
Batch
([]);
export
type
Canceller
=
()
=>
void
;
export
interface
EffStatics
{
of
:
typeof
of
,
success
:
typeof
success
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment