Skip to content

Instantly share code, notes, and snippets.

@mynameislau
Created February 18, 2018 08:11
Show Gist options
  • Save mynameislau/99cef312bbdd4bcd7d3c0a424df0d64d to your computer and use it in GitHub Desktop.
Save mynameislau/99cef312bbdd4bcd7d3c0a424df0d64d to your computer and use it in GitHub Desktop.
[...]
type mainData = {
gActions: list(gAction),
entities: list(entity),
history: list(historyChunk),
resources: int
};
open MainModel;
let createInitData = () : mainData => {
gActions: [],
entities: [EntityFactories.crewMemberFactory(0, 0), EntityFactories.crewMemberFactory(1, 0)],
history: [],
resources: 1000
};
let reduce = (state: MainModel.mainData, action: Actions.anyAction) =>
switch action {
| Actions.TickAction => {...state, resources: state.resources + 1}
| Actions.AddGActionAction => state
};
let component = ReasonReact.reducerComponent("MyForm");
let make = _children => {
...component,
initialState: MainModelCreator.createInitData,
reducer: (action, state) =>
/* this is only a simple pattern matching reducer */
ReasonReact.Update(MainReducer.reduce(state, action): MainModel.mainData),
render: self => {
<div>
<button
onClick=(_event => self.send(Actions.TickAction))
/>
/* Error : Unbound record field resources at <anonymous> */
(ReasonReact.stringToElement(string_of_int(self.state.resources)))
</div>;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment