-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing error handling as described in issue #35 #104
Open
jplikesbikes
wants to merge
2
commits into
paldepind:master
Choose a base branch
from
jplikesbikes:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Errors in flyd | ||
|
||
## Ethos | ||
+ It should not be the concern of `flyd` to handle exceptions for the user -- any `throw` should result in a hard failure. | ||
+ Silent failures are bad (current way `flyd` handles Promise.reject) | ||
+ Be as unopinionated in implementation as possible | ||
+ Be functional in design | ||
+ Be as backward compatible as possible with the current api | ||
|
||
## Concepts | ||
+ The stream is of `events` | ||
+ Each stream has a `left` and a `right` side (like an Either) | ||
+ The right side is the domain objects | ||
+ The left side is meta (in most cases errors) | ||
+ By default the api operates on the `right` side | ||
|
||
## The Api | ||
`s` is a stream | ||
|
||
### Setting data s(...) is overloaded | ||
+ `s(value)` is the default case takes a value makes it a right and pushes it down the stream | ||
+ `s(promise)` if the promise resolves pushes a right, otherwise pushes a left | ||
+ `s(either)` pushes down right or left based on either.left either.right | ||
+ `s.left(value)` sets the stream to a left of `value` | ||
|
||
### Getting data | ||
+ `s()` get the last right value or throws an exception if there is a left value | ||
+ `s.left()` get the last left value or throws an exception if there is a right value | ||
+ `s.either()` get the last value out as an Either | ||
|
||
### Checking stream state | ||
+ `s.isLeft()` return true if the stream contains a left value | ||
+ `s.isRight()` return true if the stream contains a right value | ||
|
||
### Core functions | ||
+ `.map()` works only on rights and ignores lefts | ||
+ `.mapEither()` gets all events as an `Either` | ||
+ `.combine()` and `.merge()` stay the same they work on streams | ||
+ `ap()` works on `rights` only | ||
+ `.scan()` works on `rights` only | ||
+ `.on()` works on `rights` only | ||
|
||
### The Either implementation | ||
There are no additional dependencies and we have provided a minimal implementation for basic use. If you plan on using `.mapAll` we recommend overriding the methods in flyd.Either. You can use [folktale/data.either](https://github.com/folktale/data.either) for example as shown below. | ||
``` | ||
var DE = require('data.either'); | ||
flyd.Either.Right = DE.Right; | ||
flyd.Either.Left = DE.Left; | ||
flyd.Either.isEither = function(obj) { return obj instanceof DE; }; | ||
flyd.Either.isRight = function(e) { return e.isRight; }; | ||
flyd.Either.getRight = function(e) { return e.value; }; | ||
flyd.Either.getLeft = function(e) { return e.value; }; | ||
``` | ||
|
||
### Other functionality | ||
Keeping with the ethos of flyd any further functions like `.swap` or `.onAll` should be implemented as modules. |
This file contains 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 characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding an
s.either()
that returns the left or right value ?