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

Monad API #268

Merged
merged 9 commits into from
Mar 6, 2020
Merged

Monad API #268

merged 9 commits into from
Mar 6, 2020

Conversation

kbrsh
Copy link
Owner

@kbrsh kbrsh commented Feb 18, 2020

This introduces a new API inspired by monadic IO, where an implicit RealWorld is transformed using "transformers" such as data, view, time, http, storage, or route. This allows code to be more concise, and it is also more natural for more people because it is basically imperative. The only difference is that these imperative calls must be made in a transformer, which can be registered with Moon.use and configured with Moon.configure.

A counter with this new API looks like:

const button = Moon.view.components.button;
const increment = () => {
   Moon.data.count++;
   Moon.view.render(<view/>);
};
const view = () => <button onClick=increment>{Moon.data.count}</button>;

Moon.configure({ view: { root: document.getElementById("root") } });
Moon.data.count = 0;
Moon.view.render(<view/>);

@codecov-io
Copy link

codecov-io commented Feb 18, 2020

Codecov Report

Merging #268 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #268   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          26     25    -1     
  Lines         709    645   -64     
  Branches      139    132    -7     
=====================================
- Hits          709    645   -64
Impacted Files Coverage Δ
packages/moon-compiler/src/generate.js 100% <100%> (ø) ⬆️
packages/moon/src/route/read.js 100% <100%> (ø)
packages/moon-compiler/src/parse.js 100% <100%> (ø) ⬆️
packages/moon/src/configure.js 100% <100%> (ø)
packages/moon/src/route/navigate.js 100% <100%> (ø)
packages/moon/src/route/index.js 100% <100%> (ø) ⬆️
packages/moon/src/data/index.js 100% <100%> (ø) ⬆️
packages/moon/src/view/state.js 100% <100%> (ø)
packages/moon-browser/src/index.js 100% <100%> (ø) ⬆️
packages/moon/src/storage/index.js 100% <100%> (ø) ⬆️
... and 17 more

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 6a3baf6...0e26c19. Read the comment docs.

@kbrsh kbrsh merged commit c4e65e7 into master Mar 6, 2020
@kbrsh kbrsh deleted the monad-api branch March 6, 2020 00:48
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