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

1.0.0-beta.14 | Add the new middleware system #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 27 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Removed
- `create` (both as a named export and the default export) is removed. Instead use `atom`.
- `create` (both as a named export and the default export) is removed.
- State getter's additional overload for consuming external sources is removed.

## [1.0.0-beta.14] - 2024-05-08

## [1.0.0beta-12] - 2015-02-16
### Added

- The new middleware API that's accesed via `atom.call` or `atom.bind`.

### Deprecated

- State getter's additional overload for consuming external sources is deprecated, instead use the new middleware API.

> Before:
> ```js
> const $derived = atom((get) => get(store.getState, store.subscribe))
> ```
> After:
> ```js
> const $derived = atom.call({
> get: store.getState,
> subscribe: store.subscribe
> })
> ```


## [1.0.0-beta.12] - 2024-05-02

This version, compared to the previous one only adds deprecation notices that can be fixed by slight modifications. Underlying implementations are not changed.

### Deprecated

- `create` (both as a named export and the default export) is marked as deprecated, and it has been renamed to `atom`.

> Before:
> ```js
> import create from 'xoid'
Expand All @@ -29,6 +53,7 @@ This version, compared to the previous one only adds deprecation notices that ca
> import { atom } from 'xoid'
> ```
- `inject` and `effect` exports are now exported from the root. They used to be exported from the `xoid/setup` route.

> Before:
> ```js
> import { effect, inject } from 'xoid/setup'
Expand Down
4 changes: 2 additions & 2 deletions examples/celcius-fahrenheit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react": "17.0.0",
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react": "17.0.0",
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/dots-and-arrows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"react": "18.0.0",
"react-dom": "18.0.0",
"react-scripts": "4.0.3",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"@types/react": "17.0.20",
Expand Down
4 changes: 2 additions & 2 deletions examples/finite-state-stopwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react": "17.0.0",
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/redux-devtools-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"main": "src/index.js",
"dependencies": {
"@xoid/devtools": "0.5.0",
"@xoid/react": "1.0.0-beta.12",
"@xoid/react": "1.0.0-beta.14",
"react": "17.0.0",
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"xoid": "1.0.0-beta.12"
"xoid": "1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/todos-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react": "17.0.0",
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/todos-filtered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react": "17.0.0",
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/transient-update-resize-observer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"react-dom": "17.0.0",
"react-scripts": "3.4.3",
"@juggle/resize-observer": "^3.3.1",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.8.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/use-items-abstraction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"react": "16.8.3",
"react-dom": "16.8.3",
"react-scripts": "2.1.8",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.3.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/xoid-vs-usereducer-vs-usemethods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"react-dom": "16.8.3",
"react-scripts": "2.1.8",
"use-methods": "0.4.5",
"xoid": "^1.0.0-beta.12",
"@xoid/react": "^1.0.0-beta.12"
"xoid": "^1.0.0-beta.14",
"@xoid/react": "^1.0.0-beta.14"
},
"devDependencies": {
"typescript": "3.3.3"
Expand Down
1 change: 0 additions & 1 deletion packages/deprecated/lite/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions packages/deprecated/lite/package.json

This file was deleted.

32 changes: 0 additions & 32 deletions packages/deprecated/lite/src/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"observable"
],
"peerDependencies": {
"xoid": ">=1.0.0-beta.12"
"xoid": ">=1.0.0-beta.14"
}
}
2 changes: 1 addition & 1 deletion packages/incubator/produce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"observable"
],
"peerDependencies": {
"xoid": ">=1.0.0-beta.12"
"xoid": ">=1.0.0-beta.14"
}
}
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xoid/react",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.14",
"main": "./index.js",
"module": "./index.esm.js",
"types": "./index.d.ts",
Expand Down Expand Up @@ -54,7 +54,7 @@
"use-sync-external-store": "^1.1.0"
},
"peerDependencies": {
"xoid": ">=1.0.0-beta.12",
"xoid": ">=1.0.0-beta.14",
"react": "*"
}
}
2 changes: 1 addition & 1 deletion packages/reactive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"observable"
],
"peerDependencies": {
"xoid": ">=1.0.0-beta.12"
"xoid": ">=1.0.0-beta.14"
}
}
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"observable"
],
"peerDependencies": {
"xoid": ">=1.0.0-beta.12",
"xoid": ">=1.0.0-beta.14",
"svelte": "*"
}
}
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"observable"
],
"peerDependencies": {
"xoid": ">=1.0.0-beta.12",
"xoid": ">=1.0.0-beta.14",
"vue": "<=3.1"
}
}
2 changes: 1 addition & 1 deletion packages/xoid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xoid",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.14",
"main": "./index.js",
"module": "./index.esm.js",
"types": "./index.d.ts",
Expand Down
13 changes: 7 additions & 6 deletions packages/xoid/src/atom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Atom, Stream, Init, Actions } from './internal/types'
import { createAtom, createInternal, tools } from './internal/utils'
import { createSelector } from './internal/createSelector'
import { createAtom, tools } from './internal/utils'
import { derived } from './internal/derived'
import { store } from './internal/store'

/**
* Creates an atom with the first argument as the initial state.
Expand All @@ -10,14 +11,14 @@ import { createSelector } from './internal/createSelector'
export function atom<T>(init: Init<T>): Atom<T>
export function atom<T, U>(init: Init<T>, getActions?: (a: Atom<T>) => U): Atom<T> & Actions<U>
export function atom<T>(): Stream<T>
export function atom<T, U = undefined>(init?: Init<T>, getActions?: (a: Atom<T>) => U) {
export function atom<T, U = undefined>(this, init?: Init<T>, getActions?: (a: Atom<T>) => U) {
// @ts-ignore
const internal = (typeof init === 'function' ? createSelector : createInternal)(init)
const baseStore = (typeof init === 'function' ? derived : store).call(this, init)
// @ts-ignore
internal.isStream = !arguments.length
baseStore.isStream = !arguments.length

// @ts-ignore
return createAtom(internal, getActions)
return createAtom(baseStore, getActions)
}

atom.plugins = [] as ((a: Atom<any>) => void)[]
Expand Down
5 changes: 3 additions & 2 deletions packages/xoid/src/internal/createFocus.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Store } from './store'
import { Atom } from './types'
import { createAtom, Internal } from './utils'
import { createAtom } from './utils'

export const INTERNAL = Symbol()

Expand Down Expand Up @@ -43,7 +44,7 @@ const handler = {
const pathProxy = new Proxy([], handler)

export const createFocus =
<T,>(internal: Internal<T>, basePath: string[]): Atom<T>['focus'] =>
<T,>(internal: Store<T>, basePath: string[]): Atom<T>['focus'] =>
(key: any) => {
const relativePath = typeof key === 'function' ? key(pathProxy)[INTERNAL] : [key]
if (!internal.cache) internal.cache = {}
Expand Down
Loading