Skip to content

Commit 0de7eff

Browse files
author
Wes Souza
committed
Initial commit.
0 parents  commit 0de7eff

22 files changed

+12299
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# global preferences
5+
[*]
6+
indent_style = space
7+
indent_size = 2
8+
9+
# Other preferences
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true

.github/workflows/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
on: [push]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
7+
steps:
8+
- name: Begin CI...
9+
uses: actions/checkout@v2
10+
11+
- name: Use Node 12
12+
uses: actions/setup-node@v1
13+
with:
14+
node-version: 12.x
15+
16+
- name: Use cached node_modules
17+
uses: actions/cache@v1
18+
with:
19+
path: node_modules
20+
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
21+
restore-keys: |
22+
nodeModules-
23+
24+
- name: Install dependencies
25+
run: yarn install --frozen-lockfile
26+
env:
27+
CI: true
28+
29+
- name: Lint
30+
run: yarn lint
31+
env:
32+
CI: true
33+
34+
- name: Test
35+
run: yarn test --ci --coverage --maxWorkers=2
36+
env:
37+
CI: true
38+
39+
- name: Build
40+
run: yarn build
41+
env:
42+
CI: true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.log
2+
.DS_Store
3+
node_modules
4+
.cache
5+
dist

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright © Wes Souza <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the “Software”), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# immer-state
2+
3+
This is a proof of concept of a state manager class that combines
4+
[React Hooks](https://reactjs.org/docs/hooks-reference.html),
5+
[immer](https://github.com/immerjs/immer) and an adapted
6+
[publish-subscribe pattern](https://en.wikipedia.org/wiki/Publish–subscribe_pattern).
7+
8+
See the [example files](./example/) for an idea of how this works.
9+
10+
This is a work in progress.
11+
12+
## Installation
13+
14+
```sh
15+
yarn add immer-state
16+
```
17+
18+
```js
19+
import { StateManager, useSelector } from 'https://cdn.pika.dev/immer-state@^0.1.0';
20+
```
21+
22+
## Development
23+
24+
```sh
25+
yarn install
26+
yarn run start
27+
```
28+
29+
## Example
30+
31+
```sh
32+
cd example
33+
yarn install
34+
yarn run start
35+
```
36+
37+
Then open [localhost:1234](http://localhost:1234/).
38+
39+
## LICENSE
40+
41+
MIT, https://wes.dev/LICENSE.txt

example/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.cache
3+
dist

example/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>immer-state Example</title>
8+
</head>
9+
10+
<body>
11+
<div id="root"></div>
12+
<style>
13+
html,
14+
button {
15+
font-family: sans-serif;
16+
font-size: 1.2em;
17+
}
18+
</style>
19+
<script src="./index.tsx"></script>
20+
</body>
21+
</html>

example/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
import 'react-app-polyfill/ie11';
3+
import * as ReactDOM from 'react-dom';
4+
5+
import { useSelector } from '../dist';
6+
7+
import { counterIncrement } from './state/counter.actions';
8+
import { getCounterCurrent } from './state/counter.selectors';
9+
import { counterStore } from './state/counter.store';
10+
11+
function App() {
12+
const current = useSelector(counterStore, getCounterCurrent);
13+
14+
return (
15+
<main>
16+
<h1>immer-state Example</h1>
17+
<p>Counter: {current}</p>
18+
<p>
19+
<button onClick={counterIncrement}>Increment</button>
20+
</p>
21+
</main>
22+
);
23+
}
24+
25+
ReactDOM.render(<App />, document.getElementById('root'));

example/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "immer-state-example",
3+
"version": "0.1.0",
4+
"main": "index.html",
5+
"license": "MIT",
6+
"scripts": {
7+
"start": "parcel index.html",
8+
"build": "parcel build index.html"
9+
},
10+
"dependencies": {
11+
"react-app-polyfill": "^1.0.6",
12+
"state": "^0.2.0"
13+
},
14+
"alias": {
15+
"react": "../node_modules/react",
16+
"react-dom": "../node_modules/react-dom/profiling",
17+
"scheduler/tracing": "../node_modules/scheduler/tracing-profiling"
18+
},
19+
"devDependencies": {
20+
"@types/react": "^16.9.31",
21+
"@types/react-dom": "^16.9.6",
22+
"parcel": "^1.12.4",
23+
"typescript": "^3.8.3"
24+
}
25+
}

example/state/counter.actions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { counterStore } from './counter.store';
2+
3+
export function counterIncrement() {
4+
counterStore.mutate((state) => {
5+
state.current += 1;
6+
});
7+
}

0 commit comments

Comments
 (0)