Skip to content

Instantly share code, notes, and snippets.

View coffee-cup's full-sized avatar

Jake Runzer coffee-cup

View GitHub Profile
import * as React from "react";
import { state, watch, dispatch } from "./model";
import { increaseCount, decreaseCount } from "./actions";
export const App = () => (
<div>
<button onClick={() => dispatch(decreaseCount)()}>-</button>
<h1>Count: {watch(state.count)}</h1>
<button onClick={() => dispatch(increaseCount)()}>+</button>
</div>);
import { state } from "./model";
const increaseCount = () => {
state.count++;
};
const decreaseCount = () => {
state.count--;
};
import { model } from "./model";
const { Provider } = model.createStore({
initState: {
count: 0,
},
});
// src/model.ts
import { createModel } from "@prodo/core";
interface State {
count: number;
}
export const model = createModel<State>();
export const { state, watch, dispatch } = model.ctx;
import * as React from "react";
import { useOvermind } from "./overmind";
const Counter: React.FC = () => {
const { state, actions } = useApp();
return (
<div className="App">
<h1>{state.count}</h1>
<button onClick={() => actions.decreaseCount()}>decrease</button>
<button onClick={() => actions.increaseCount()}>increase</button>
// src/overrmind/index.ts
export const config = {
state: { /* ... */ },
actions: { /* ... */ }
}
export const useOvermind = createHook<typeof config>()
import { Action } from './overmind'
export const noArgAction: Action = (context, value) => {
value // this becomes "void"
}
export const argAction: Action<string> = (context, value) => {
value // this becomes "string"
}
// src/overmind/index.ts
import {
IConfig,
IOnInitialize,
IAction,
IOperator,
IDerive,
IState
} from 'overmind'
// src/overmind/index.ts
import { IConfig } from 'overmind'
const config = {
state: {
count: 0
},
actions: {
increaseCount({ state }) {
state.count++;
import * as React from "react";
import { useStore } from "../store";
const MyComponent = observer((props: Props) => {
const store = useStores();
return (/* ... */;
});