Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Overmind #144

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
| [ReComponent](https://github.com/philipp-spiess/react-recomponent) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/react-recomponent) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/react-recomponent) | Coming Soon - Contribute Here? |
| [undux](https://github.com/bcherny/undux) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/undux) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/undux) | Coming Soon - Contribute Here? |
| [React 16.7.0-alpha useState Hook](https://reactjs.org/docs/hooks-overview.html) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/31420no9pq) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/useState) | Coming Soon - Contribute Here? |
| [redux-lightweight](https://github.com/doniyor2109/redux-lightweight) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/redux-lightweight) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/redux-lightweight) | Coming Soon - Contribute Here? |
| [redux-lightweight](https://github.com/doniyor2109/redux-lightweight) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/redux-lightweight) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/redux-lightweight) | Coming Soon - Contribute Here? |
| [overmind](https://overmindjs.org/?view=react&typescript=false) | [<img src="./_art/csb.png" width="40px" />](https://codesandbox.io/s/github/GantMan/ReactStateMuseum/tree/master/React/overmind) [<img src="./_art/octo.png" width="36px" />](https://github.com/GantMan/ReactStateMuseum/tree/master/React/overmind) | Coming Soon - Contribute Here? |

### Examples to help portray the how, why, which, pros, and cons of various state management systems in the React ecosystem.

Expand Down
23 changes: 23 additions & 0 deletions React/overmind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
5 changes: 5 additions & 0 deletions React/overmind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
If you use yarn, run:
`yarn && yarn start`

If you use npm, run:
`npm i && npm run start`
19 changes: 19 additions & 0 deletions React/overmind/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "overmind",
"version": "0.1.0",
"description": "React State Museum - Example of Overmind",
"dependencies": {
"overmind": "^20.0.0",
"overmind-react": "^21.0.0",
"packlist-components": "1.2.0",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-scripts": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
40 changes: 40 additions & 0 deletions React/overmind/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
21 changes: 21 additions & 0 deletions React/overmind/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";

import ListItems from "./Components/listItems";
import AddItems from "./Components/addItem";

const styles = {
fontFamily: "sans-serif",
textAlign: "center"
};

const App = () => {
return (
<div style={styles}>
<h2>Welcome to Overmind</h2>
<AddItems />
<ListItems />
</div>
);
};

export default App;
19 changes: 19 additions & 0 deletions React/overmind/src/Components/addItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { AddPackingItem } from "packlist-components";

import { useApp } from "../Overmind/store";

const AddItems = () => {
const { actions, state } = useApp();

return (
<AddPackingItem
addItem={actions.addItem}
setNewItemText={event => actions.setNewItemName(event.target.value)}
value={state.newItemName}
clear={actions.clear}
/>
);
};

export default AddItems;
12 changes: 12 additions & 0 deletions React/overmind/src/Components/listItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { SimpleList } from "packlist-components";

import { useApp } from "../Overmind/store";

const ListItems = () => {
const { state } = useApp();

return <SimpleList value={state.items} />;
};

export default ListItems;
29 changes: 29 additions & 0 deletions React/overmind/src/Overmind/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createOvermind } from "overmind";
import { createHook } from "overmind-react";

export const useApp = createHook();

export const overmind = createOvermind(
{
state: {
newItemName: "",
items: ["nacho", "burrito", "hotdog"]
},
actions: {
setNewItemName({ state }, itemName) {
state.newItemName = itemName;
},
addItem({ state }) {
state.items = [...state.items, state.newItemName];

state.newItemName = "";
},
clear({ state }) {
state.items = [];
}
}
},
{
devtools: false
}
);
21 changes: 21 additions & 0 deletions React/overmind/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/************************************************
* This example is one of many examples
* -= The React State Museum =-
* View other state management options and read
* more in the blog post and the master repo:
*
* https://github.com/GantMan/ReactStateMuseum
************************************************/
import React from "react";
import { render } from "react-dom";
import { Provider } from "overmind-react";

import App from "./App";
import { overmind } from "./Overmind/store";

render(
<Provider value={overmind}>
<App />
</Provider>,
document.getElementById("root")
);
Loading