Skip to content

Commit

Permalink
Meiosis examples v0.4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
foxdonut committed May 7, 2016
1 parent ffcd8a2 commit 5107407
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 49 deletions.
4 changes: 2 additions & 2 deletions labeled-sliders/labeledSlider/view.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import h from "snabbdom/h";
const { div, input, span } = require("hyperscript-helpers")(h);

const view = ({actions, measurement, index}) => {
const view = ({measurement, index}, actions) => {
const getValue = evt => parseInt(evt.target.value, 10);
const onChangeValue = evt => actions.next({index, value: getValue(evt)});
const onChangeValue = evt => actions.sendUpdate({index, value: getValue(evt)});

return (
div([
Expand Down
16 changes: 3 additions & 13 deletions labeled-sliders/sliderContainer/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assoc, merge } from "ramda";
import { Action } from "./actions";
import { initialModel, transform } from "./model";
import { initialModel } from "./model";
import receiveUpdate from "./receiveUpdate";
import view from "./view";

import createLabeledSlider from "../labeledSlider/main";
Expand All @@ -11,16 +10,7 @@ const createSliderContainer = createComponent => {
return createComponent({
initialModel,
view: view(LabeledSlider),
transform: transform(Action),
receivers: [(model, update) => {
if (parseInt(update.index, 10) >= 0) {
model.measurements[update.index] = assoc("value", update.value, model.measurements[update.index]);
}
else {
model = merge(model, update);
}
return model;
}]
receiveUpdate: receiveUpdate
});
};

Expand Down
26 changes: 1 addition & 25 deletions labeled-sliders/sliderContainer/model.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
import { append, assoc } from "ramda";

const initialModel = {
measurements: [],
nextId: 0
};

const rnd = (min, max) => Math.round(Math.random() * min) + (max || 0);

const transform = Action => (model, action) => Action.case({
AddMeasurement: () =>
assoc("nextId",
model.nextId + 1,
assoc("measurements",
append({
id: model.nextId,
label: "Measurement",
value: rnd(50),
max: rnd(50,100),
units: rnd(10) % 2 === 0 ? "cm" : "mm"
}, model.measurements),
model
)
),

RemoveMeasurement: id =>
assoc("measurements", model.measurements.filter(m => m.id !== id), model)
}, action);

export { initialModel, transform };
export { initialModel };
36 changes: 36 additions & 0 deletions labeled-sliders/sliderContainer/receiveUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { append, assoc, merge } from "ramda";
import { Action } from "./actions";

const rnd = (min, max) => Math.round(Math.random() * min) + (max || 0);

const transform = (model, action) => Action.case({
AddMeasurement: () =>
assoc("nextId",
model.nextId + 1,
assoc("measurements",
append({
id: model.nextId,
label: "Measurement",
value: rnd(50),
max: rnd(50,100),
units: rnd(10) % 2 === 0 ? "cm" : "mm"
}, model.measurements),
model
)
),

RemoveMeasurement: id =>
assoc("measurements", model.measurements.filter(m => m.id !== id), model)
}, action);

const receiveUpdate = (model, update) => {
if (parseInt(update.index, 10) >= 0) {
model.measurements[update.index] = assoc("value", update.value, model.measurements[update.index]);
}
else {
model = merge(model, transform(model, update));
}
return model;
};

export default receiveUpdate;
10 changes: 5 additions & 5 deletions labeled-sliders/sliderContainer/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const { div } = require("hyperscript-helpers")(h);

import { Action } from "./actions";

const view = LabeledSlider => ({model, actions}) => {
const onAddMeasurement = _evt => actions.next(Action.AddMeasurement());
const onRemoveMeasurement = id => actions.next(Action.RemoveMeasurement(id));
const view = LabeledSlider => (model, actions) => {
const onAddMeasurement = _evt => actions.sendUpdate(Action.AddMeasurement());
const onRemoveMeasurement = id => actions.sendUpdate(Action.RemoveMeasurement(id));

const renderMeasurement = (measurement, index) =>
const renderMeasurement = (measurement, index) =>
div({key: measurement.id, style: {border: "1px solid gray"}, id: measurement.id}, [
LabeledSlider({actions, measurement, index}),
LabeledSlider({measurement, index}, actions),
div([
h("button.btn.btn-danger.btn-sm",
{on: {click: [onRemoveMeasurement, measurement.id]}}, "Remove Measurement")
Expand Down
2 changes: 1 addition & 1 deletion todomvc/js/meiosis-tracer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5107407

Please sign in to comment.