Skip to content

Commit

Permalink
update of deps
Browse files Browse the repository at this point in the history
  • Loading branch information
limemloh committed Feb 26, 2019
1 parent f598870 commit 74d8899
Show file tree
Hide file tree
Showing 20 changed files with 556 additions and 935 deletions.
249 changes: 114 additions & 135 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/continuous-time/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Behavior,
map,
sample,
snapshot,
stepper,
Stream,
Expand All @@ -28,8 +27,9 @@ const model = fgo(function*({ snapClick }: ViewOut) {
(t) => "You last pressed the button at " + formatTime(t),
snapshot(time, snapClick)
);
const message = yield sample(
stepper("You've not clicked the button yet", msgFromClick)
const message = yield stepper(
"You've not clicked the button yet",
msgFromClick
);
return { time, message };
});
Expand Down
15 changes: 4 additions & 11 deletions examples/counters/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { Behavior, combine, sample, stepper, Stream } from "@funkia/hareactive";
import { Behavior, combine, stepper, Stream } from "@funkia/hareactive";
import { go } from "@funkia/jabz";
import {
Component,
dynamic,
elements,
fgo,
modelView,
runComponent
} from "../../../src";
import { elements, fgo, modelView, runComponent } from "../../../src";
import { main1 } from "./version1";
import { main2 } from "./version2";
import { main3 } from "./version3";
Expand Down Expand Up @@ -45,7 +38,7 @@ type FromModel = {

const versionSelector = modelView<FromModel, FromView>(
fgo(function*({ selectVersion }) {
const selected = yield sample(stepper("1", selectVersion));
const selected = yield stepper("1", selectVersion);
return { selected };
}),
({ selected }) =>
Expand All @@ -64,7 +57,7 @@ const versionSelector = modelView<FromModel, FromView>(
const main = go(function*() {
const { selected } = yield versionSelector();
const currentApp = selected.map((n: AppId) => numberToApp[n]);
yield div(dynamic(currentApp));
yield div(currentApp);
return {};
});

Expand Down
5 changes: 2 additions & 3 deletions examples/counters/src/version1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Stream } from "@funkia/hareactive";
import { elements, Component } from "../../../src";
const { br, div, button } = elements;
import { elements } from "../../../src";
const { div, button } = elements;

// Counter
const counterView = div([
Expand Down
8 changes: 4 additions & 4 deletions examples/counters/src/version2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Behavior, sample, scan, Stream, combine } from "@funkia/hareactive";
import { elements, modelView, Component, fgo } from "../../../src";
const { br, div, button } = elements;
import { Behavior, accum, Stream, combine } from "@funkia/hareactive";
import { elements, modelView, fgo } from "../../../src";
const { div, button } = elements;

type CounterModelInput = {
incrementClick: Stream<any>;
Expand All @@ -18,7 +18,7 @@ const counterModel = fgo(function*({
const increment = incrementClick.mapTo(1);
const decrement = decrementClick.mapTo(-1);
const changes = combine(increment, decrement);
const count = yield sample(scan((n, m) => n + m, 0, changes));
const count = yield accum((n, m) => n + m, 0, changes);
return { count };
});

Expand Down
18 changes: 10 additions & 8 deletions examples/counters/src/version3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import {
combine,
map,
Now,
sample,
accum,
scan,
scanS,
Stream
} from "@funkia/hareactive";

import { elements, fgo, list, ModelReturn, modelView } from "../../../src";
const { br, div, button, h1, ul } = elements;

const add = (n: number, m: number) => n + m;
const apply = <A>(f: (a: A) => A, a: A) => f(a);
const apply = <A, B>(f: (a: A) => B, a: A) => f(a);

type CounterModelInput = {
incrementClick: Stream<any>;
Expand All @@ -33,7 +33,7 @@ const counterModel = fgo(function*({
}: CounterModelInput): ModelReturn<CounterViewInput> {
const increment = incrementClick.mapTo(1);
const decrement = decrementClick.mapTo(-1);
const count = yield sample(scan(add, 0, combine(increment, decrement)));
const count = yield accum(add, 0, combine(increment, decrement));
return { count };
});

Expand Down Expand Up @@ -67,14 +67,16 @@ const counterListModel = fgo(function*({
addCounter,
listOut
}: ModelInput): Iterator<Now<any>> {
const nextId: Stream<number> = yield sample(
scanS(add, 2, addCounter.mapTo(1))
);
const nextId: Stream<number> = yield scan(add, 2, addCounter.mapTo(1));
const appendCounterFn = map(
(id) => (ids: number[]) => ids.concat([id]),
nextId
);
const counterIds = yield sample(scan(apply, [0], appendCounterFn));
const counterIds = yield accum<(a: number[]) => number[], number[]>(
apply,
[0],
appendCounterFn
);
return { counterIds };
});

Expand Down
22 changes: 10 additions & 12 deletions examples/counters/src/version4.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { foldr, lift, flatten } from "@funkia/jabz";
import {
Now,
sample,
Behavior,
scan,
Stream,
combine,
map,
switchStream,
scanS
accum,
shiftCurrent,
empty
} from "@funkia/hareactive";

import { Component, modelView, list, elements, fgo } from "../../../src";
import { modelView, list, elements, fgo } from "../../../src";
const { ul, li, p, br, button, h1 } = elements;

const add = (n: number, m: number) => n + m;
Expand Down Expand Up @@ -43,7 +43,7 @@ const counterModel = fgo(function*(
const increment = incrementClick.mapTo(1);
const decrement = decrementClick.mapTo(-1);
const deleteS = deleteClick.mapTo(id);
const count = yield sample(scan(add, 0, combine(increment, decrement)));
const count = yield accum(add, 0, combine(increment, decrement));
return { count, deleteS };
});

Expand Down Expand Up @@ -82,8 +82,8 @@ const mainModel = fgo(function*({
addCounter,
listOut
}: ToModel): Iterator<Now<any>> {
const removeIdB = listOut.map(
(l) => console.log(l) || combine(...l.map((o) => o.deleteS))
const removeIdB = listOut.map((l) =>
l.length > 0 ? combine(...l.map((o) => o.deleteS)) : <Stream<number>>empty
);
const sum = <Behavior<number>>(
flatten(
Expand All @@ -98,15 +98,13 @@ const mainModel = fgo(function*({
)
)
);
const removeCounterIdFn = switchStream(removeIdB).map(
const removeCounterIdFn = shiftCurrent(removeIdB).map(
(id) => (arr: number[]) => arr.filter((i) => i !== id)
);
const nextId: Stream<number> = yield sample(
scanS(add, 2, addCounter.mapTo(1))
);
const nextId: Stream<number> = yield scan(add, 2, addCounter.mapTo(1));
const appendCounterFn = map((id) => (ids: Id[]) => ids.concat([id]), nextId);
const modifications = combine(appendCounterFn, removeCounterIdFn);
const counterIds = yield sample(scan(apply, [0, 1, 2], modifications));
const counterIds = yield accum(apply, [0, 1, 2], modifications);
return { counterIds, sum };
});

Expand Down
30 changes: 15 additions & 15 deletions examples/drag/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import {
streamFromEvent,
stepper,
toggle,
sample,
snapshot,
switcher,
Behavior,
combine,
scan
lift,
runNow,
Stream,
accum
} from "@funkia/hareactive";
import { lift } from "@funkia/jabz";
import { runComponent, elements, go, fgo, modelView } from "../../../src";
const { div } = elements;

type Point = { x: number; y: number };

const mousemove = streamFromEvent(window, "mousemove");
const mousePosition = stepper(
{ x: 0, y: 0 },
mousemove.map((e) => ({ x: e.pageX, y: e.pageY }))
).at();
const mousePosition = runNow(
stepper({ x: 0, y: 0 }, mousemove.map((e) => ({ x: e.pageX, y: e.pageY })))
);

const addPoint = (p1: Point, p2: Point) => ({
x: p1.x + p2.x,
Expand All @@ -41,17 +41,17 @@ const boxModel = fgo(function*(
(p) => map((p2) => ({ x: p2.x - p.x, y: p2.y - p.y }), mousePosition),
startDragAt
);
const offset: Behavior<Point> = yield sample(
switcher(
Behavior.of({ x: 0, y: 0 }),
combine(dragOffset, endDrag.mapTo(Behavior.of({ x: 0, y: 0 })))
)
const offset: Behavior<Point> = yield switcher(
Behavior.of({ x: 0, y: 0 }),
combine(dragOffset, endDrag.mapTo(Behavior.of({ x: 0, y: 0 })))
);
const committed = yield sample(
scan(addPoint, { x: 0, y: 0 }, snapshot(offset, endDrag))
const committed: Behavior<Point> = yield accum(
addPoint,
{ x: 0, y: 0 },
snapshot(offset, endDrag)
);
const position = lift(addPoint, committed, offset);
const isBeingDragged = yield sample(toggle(false, startDrag, endDrag));
const isBeingDragged = yield toggle(false, startDrag, endDrag);
return { isBeingDragged, position };
});

Expand Down
20 changes: 8 additions & 12 deletions examples/fahrenheit-celsius/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Behavior, combine, sample, stepper, Stream } from "@funkia/hareactive";
import { elements, fgo, modelView, runComponent, toComponent } from "../../src";
import { Behavior, combine, stepper, Stream } from "@funkia/hareactive";
import { elements, fgo, modelView, runComponent } from "../../src";

const { input, div, label } = elements;

Expand All @@ -21,17 +21,13 @@ const parseNumbers = (s: Stream<string>) =>
const model = fgo(function*({ fahrenChange, celsiusChange }: View) {
const fahrenNrChange = parseNumbers(fahrenChange);
const celsiusNrChange = parseNumbers(celsiusChange);
const celsius = yield sample(
stepper(
0,
combine(celsiusNrChange, fahrenNrChange.map((f) => (f - 32) / 1.8))
)
const celsius = yield stepper(
0,
combine(celsiusNrChange, fahrenNrChange.map((f) => (f - 32) / 1.8))
);
const fahren = yield sample(
stepper(
0,
combine(fahrenNrChange, celsiusNrChange.map((c) => (c * 9) / 5 + 32))
)
const fahren = yield stepper(
0,
combine(fahrenNrChange, celsiusNrChange.map((c) => (c * 9) / 5 + 32))
);
return { celsius, fahren };
});
Expand Down
Loading

0 comments on commit 74d8899

Please sign in to comment.