-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from funkia/new-component-function
New component function, refactor TodoMVC
- Loading branch information
Showing
15 changed files
with
603 additions
and
699 deletions.
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
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 |
---|---|---|
@@ -1,41 +1,32 @@ | ||
import { Behavior, accum, Stream, combine } from "@funkia/hareactive"; | ||
import { elements, modelView, fgo } from "../../../src"; | ||
import { elements, fgo, component } from "../../../src"; | ||
const { div, button } = elements; | ||
|
||
type CounterModelInput = { | ||
type On = { | ||
incrementClick: Stream<any>; | ||
decrementClick: Stream<any>; | ||
}; | ||
|
||
type CounterViewInput = { | ||
count: Behavior<number>; | ||
}; | ||
|
||
const counterModel = fgo(function*({ | ||
incrementClick, | ||
decrementClick | ||
}: CounterModelInput) { | ||
const increment = incrementClick.mapTo(1); | ||
const decrement = decrementClick.mapTo(-1); | ||
const changes = combine(increment, decrement); | ||
const count = yield accum((n, m) => n + m, 0, changes); | ||
return { count }; | ||
}); | ||
|
||
const counterView = ({ count }: CounterViewInput) => | ||
div([ | ||
"Counter ", | ||
count, | ||
" ", | ||
button({ class: "btn btn-default" }, " + ").output({ | ||
incrementClick: "click" | ||
}), | ||
" ", | ||
button({ class: "btn btn-default" }, " - ").output({ | ||
decrementClick: "click" | ||
}) | ||
]); | ||
const counter = component<On>( | ||
fgo(function*({ incrementClick, decrementClick }) { | ||
const increment = incrementClick.mapTo(1); | ||
const decrement = decrementClick.mapTo(-1); | ||
const changes = combine(increment, decrement); | ||
const count = yield accum((n, m) => n + m, 0, changes); | ||
|
||
const counter = modelView(counterModel, counterView); | ||
return div([ | ||
"Counter ", | ||
count, | ||
" ", | ||
button({ class: "btn btn-default" }, " + ").output({ | ||
incrementClick: "click" | ||
}), | ||
" ", | ||
button({ class: "btn btn-default" }, " - ").output({ | ||
decrementClick: "click" | ||
}) | ||
]); | ||
}) | ||
); | ||
|
||
export const main2 = counter(); | ||
export const main2 = counter; |
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.