kbrsh / moon

🌙 The minimal & fast library for functional user interfaces
https://moonjs.org
MIT License
6k stars 200 forks source link

Monad API #268

Closed kbrsh closed 4 years ago

kbrsh commented 4 years ago

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 commented 4 years ago

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%> (ø) :arrow_up:
packages/moon/src/route/read.js 100% <100%> (ø)
packages/moon-compiler/src/parse.js 100% <100%> (ø) :arrow_up:
packages/moon/src/configure.js 100% <100%> (ø)
packages/moon/src/route/navigate.js 100% <100%> (ø)
packages/moon/src/route/index.js 100% <100%> (ø) :arrow_up:
packages/moon/src/data/index.js 100% <100%> (ø) :arrow_up:
packages/moon/src/view/state.js 100% <100%> (ø)
packages/moon-browser/src/index.js 100% <100%> (ø) :arrow_up:
packages/moon/src/storage/index.js 100% <100%> (ø) :arrow_up:
... 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.