Skip to content
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

Document moment #66

Merged
merged 1 commit into from
Jul 6, 2019
Merged

Document moment #66

merged 1 commit into from
Jul 6, 2019

Conversation

paldepind
Copy link
Member

Related to #64. What do you think @deklanw? Does this make sense?

@funkia funkia deleted a comment from codecov bot Jun 29, 2019
Copy link

@deklanw deklanw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks good 👍

README.md Outdated
@@ -682,6 +682,66 @@ occurrence in `source` the function is applied to the current value of
the behaviour and the value of the occurrence, the returned value
becomes the next value of the behavior.

#### `moment<A>(f: (sample: <B>(b: Behavior<B>) => B) => A): Behavior<A>``
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra ` messes up formatting

README.md Outdated
```

The above could also be achieved with `lift`. However, `moment` can do many
things that `lift` can't. For instance, `moment` can give better performance
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why better performance?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the question.

If you write something like this:

const lifted = lift((a, b, c, d) => a && b ? c : d, aB, bB, cB, dB);

Then the resulting behavior will always depend on both aB, bB, cB, dB. This means that if any of them changes then the value of lifted will be recomputed. But, clearly we can see that if, for instance, aB is false then the function actually only uses aB and there is no need to recompute lifted if any of the other behaviors changes. However, Hareactive can't know that since the function is just a "black box".

If, on the other hand, we use moment:

const momented = moment((at) => at(aB) && at(bB) ? at(cB) : at(dB));

Then Hareactive can simply check which behaviors are actually sampled inside the function passed to moment, and it uses this information to figure out which behaviors momented depends upon in any given time. This means that when aB is false then Hareactive can figure out that currently momented only depends on atB and there is no need to recompute it when any of the other behaviors changes.

Does that make sense or should I attempt to explain it better? Should I explain it better in the documentation?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That explanation makes sense to me. I think you could put that right into the docs. (Also, the typo above!)

@codecov
Copy link

codecov bot commented Jul 6, 2019

Codecov Report

Merging #66 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #66   +/-   ##
=======================================
  Coverage   95.65%   95.65%           
=======================================
  Files          13       13           
  Lines        1359     1359           
  Branches       60       60           
=======================================
  Hits         1300     1300           
  Misses         59       59

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b962891...c13b033. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Jul 6, 2019

Codecov Report

Merging #66 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #66   +/-   ##
=======================================
  Coverage   95.65%   95.65%           
=======================================
  Files          13       13           
  Lines        1359     1359           
  Branches       60       60           
=======================================
  Hits         1300     1300           
  Misses         59       59

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b962891...c13b033. Read the comment docs.

@paldepind
Copy link
Member Author

Thanks a lot for the feedback @deklanw 😄 I've updated the PR as you suggested and fixed the typo you caught.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants