Skip to content

Commit

Permalink
draft refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Jul 2, 2021
1 parent d8f33c8 commit ad7ffdc
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 439 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

100 changes: 0 additions & 100 deletions .eslintrc

This file was deleted.

6 changes: 0 additions & 6 deletions .huskyrc

This file was deleted.

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
node_modules/
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"trailingComma": "all",
"singleQuote": true,
"trailingComma": "all",
"semi": false
}
5 changes: 5 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Architecture

## Challenges

- fork atom with state scopes is not scoping dependent actions
80 changes: 6 additions & 74 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,8 @@
## 1.0.0-rc10
# Changelog

Add `getIsAction` and `getIsAtom` to public API
## v2*

## 1.0.0-rc6

Rewrite core, remove domains as unnecessary (now).

## 1.0.0

`flaxom` -> `reatom`

`createAction` -> `declareAction`

`createAtom` -> `declareAtom`

## 4.0.0

Core improvements and bugs fixes...

(!) Move to **Reatom** package (!)

## 3.0.10

Improve API naming

> `createReducer` -> `createAtom`
## 3.0.9

Add warning for production

## 3.0.8

Update readme

## 3.0.0 - 3.0.7

Improve edge-cases for [store] lazy reducers

## 3.0.0

New API for best static type inference

```js
createReducer(
'name',
initialState,
handle => [
handle(action, (state, payload) => ...)
handle(reducer1, (state, reducer1State) => ...)
],
)
```

## 2.0.0

`redux-steroid` -> `flaxom`

## 1.7.0

- Improve `store.getState()` API (getState without arguments now equal `getStateInternal`)
- Add `asId` API for strict declaration of ActionTypes and Ids (useful for snapshots)
- Add middleware to store

## 1.6.0

- Add lazy reducers to createStore

## 1.5.0

- Rewrite core - improve bundle size and performance

## 1.4.0

- Add `createStore` - a half compatible **redux**-like API
- Atoms state is no longer autocleaning after dependent subscriptions clear.
> It use `WeakMap` so it is safe to memory leaks and more predictable (intuitive)
- Atoms may receive actions ever they have no any dependent subscriptions, if action includes link to atom/s in `target` field.
> It used in atoms "methods"
36 changes: 0 additions & 36 deletions SUMMARY.md

This file was deleted.

14 changes: 0 additions & 14 deletions babel.config.js

This file was deleted.

12 changes: 6 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ const increment = declareAction()
const add = declareAction()

/** Atoms */
const countAtom = declareAtom(1, on => [
on(increment, state => state + 1),
const countAtom = declareAtom(1, (on) => [
on(increment, (state) => state + 1),
on(add, (state, payload) => state + payload),
])
const isOddAtom = map(countAtom, count => Boolean(count % 2))
const isOddAtom = map(countAtom, (count) => Boolean(count % 2))

/** Store */
const store = createStore()

store.subscribe(countAtom, count => console.log('`count` state: ', count))
store.subscribe(isOddAtom, isOdd => console.log('`isOdd` state: ', isOdd))
store.subscribe(add, payload => console.log('`add` payload: ', payload))
store.subscribe(countAtom, (count) => console.log('`count` state: ', count))
store.subscribe(isOddAtom, (isOdd) => console.log('`isOdd` state: ', isOdd))
store.subscribe(add, (payload) => console.log('`add` payload: ', payload))

store.dispatch(increment())
// `count` state: 2
Expand Down
10 changes: 6 additions & 4 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('simple counter', () => {
0,
// callback for creating
// list of dependencies and their transformations
on => [on(increment, state => state + 1)],
(on) => [on(increment, (state) => state + 1)],
)

const store = createStore(counterAtom)
Expand All @@ -27,8 +27,10 @@ test('simple counter', () => {
```js
test('derived (computed) atoms', () => {
const increment = declareAction()
const counterAtom = declareAtom(0, on => [on(increment, state => state + 1)])
const counterDoubledAtom = map(counterAtom, value => value * 2)
const counterAtom = declareAtom(0, (on) => [
on(increment, (state) => state + 1),
])
const counterDoubledAtom = map(counterAtom, (value) => value * 2)
const countersShapeAtom = combine([counterAtom, counterDoubledAtom])

const store = createStore(countersShapeAtom)
Expand All @@ -51,7 +53,7 @@ test('side effects', async () => {
await delay()
if (incrementCallId === lastCallId) store.dispatch(setValue(payload))
})
const valueAtom = declareAtom(0, on => [
const valueAtom = declareAtom(0, (on) => [
on(setValue, (state, payload) => payload),
])
const store = createStore(valueAtom)
Expand Down
14 changes: 7 additions & 7 deletions docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const fetchUserDone = declareAction()
const fetchUser = declareAction(
name, // or type - optional
(payload, store) =>
fetch('/user', payload).then(response =>
fetch('/user', payload).then((response) =>
store.dispatch(fetchUserDone(response)),
),
)
Expand All @@ -81,15 +81,15 @@ import { declareAtom } from '@reatom/core'
const countAtom = declareAtom(
'count', // name (optional!)
0, // initial state
on => [
(on) => [
// reducers definitions:
// `on(dependedDeclaredActionOrAtom, reducer)`
// reducer: (oldState, dependedValues) => newState
on(increment, state => state + 1),
on(increment, (state) => state + 1),
on(add, (state, payload) => state + payload),
],
)
const countDoubledAtom = declareAtom(0, on => [
const countDoubledAtom = declareAtom(0, (on) => [
on(countAtom, (state, count) => count * 2),
])
// shortcut:
Expand All @@ -111,7 +111,7 @@ If you need to dynamically generate atom state (on subscription) you can derive
```js
import { init } from '@reatom/core'

const dateAtom = declareAtom(Date.now(), on => [on(init, () => Date.now())])
const dateAtom = declareAtom(Date.now(), (on) => [on(init, () => Date.now())])
```

> **NOTE**. See FAQ on [why declare\*](/faq?id=why-declare)
Expand All @@ -138,8 +138,8 @@ store.dispatch(declaredAction(payload))

/* SUBSCRIBING */

store.subscribe(atom, atomValue => 'side effect')
store.subscribe(declaredAction, actionPayload => 'side effect')
store.subscribe(atom, (atomValue) => 'side effect')
store.subscribe(declaredAction, (actionPayload) => 'side effect')
store.subscribe((dispatchedAction, stateDiff) => 'side effect')

/* STATE */
Expand Down
3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions lerna.json

This file was deleted.

Loading

0 comments on commit ad7ffdc

Please sign in to comment.