Skip to content

Commit

Permalink
Merge pull request #18 from dottostack/feat/react
Browse files Browse the repository at this point in the history
fix: delete unused packages
  • Loading branch information
eddort authored Aug 21, 2021
2 parents 4145638 + ab8d23d commit 2d59b2b
Show file tree
Hide file tree
Showing 25 changed files with 320 additions and 42 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
},
"devDependencies": {
"@release-it/conventional-changelog": "^3.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"release-it": "^14.11.5",
"release-it-yarn-workspaces-clean-publish": "^0.0.4",
"yarn-changed-workspaces": "^2.0.10"
Expand Down
2 changes: 1 addition & 1 deletion packages/dotto.x/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">dotto.x</h1>

<img align="right" src="logo.png" width="200px" alt="dotto.x - lightweight state manager">
<img align="right" src="https://raw.githubusercontent.com/dottostack/dotto.x/main/logo.png" width="200px" alt="dotto.x - lightweight state manager">

A tiny state manager for **React**
and vanilla JS. (other frameworks in future)
Expand Down
14 changes: 14 additions & 0 deletions packages/dotto.x/bind/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DotXStore } from '../create-store'
import { ResolveType } from '../utils/get'

export interface BindedStore<Data, Path> {
subscribe: (cb: (result: ResolveType<Data, Path>) => void) => () => void
listen: (cb: (result: ResolveType<Data, Path>) => void) => () => void
get: () => ResolveType<Data, Path>
set: (payload: ResolveType<Data, Path>) => ResolveType<Data, Path>
}

export function bind<Data, Path extends string>(
store: DotXStore<Data>,
path: Path
): BindedStore<Data, Path>
7 changes: 7 additions & 0 deletions packages/dotto.x/bind/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { computed, take } from '../computed'

export const bind = (store, path) => {
let bindedStore = computed(() => take(store, path))
bindedStore.set = store.set.bind(store, path)
return bindedStore
}
17 changes: 17 additions & 0 deletions packages/dotto.x/bind/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createStore } from '../create-store'
import { bind } from './index'

describe('bind', () => {
it('get', () => {
let store = createStore({ some: 1 })
let some = bind(store, 'some')
expect(some.get()).toBe(1)
})
it('set', () => {
let store = createStore({ some: 1 })
let some = bind(store, 'some')
expect(some.set(2)).toBe(2)
expect(some.get()).toBe(2)
expect(store.get('some')).toBe(2)
})
})
2 changes: 1 addition & 1 deletion packages/dotto.x/computed/computed.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ReadableStore<Cb> = {
export interface ReadableStore<Cb> {
subscribe: (cb: (result: ReturnType<Cb>) => void) => () => void
listen: (cb: (result: ReturnType<Cb>) => void) => () => void
get: () => ReturnType<Cb>
Expand Down
4 changes: 2 additions & 2 deletions packages/dotto.x/computed/take.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { target } from './context'

export const take = (store, query) => {
if (!store.set) return store.get(true)
if (store._run) return store.get(true)
let container = target()
return container.silent
return !container || container.silent
? store.get(query)
: (container.add(store, query), store.get(query))
}
3 changes: 2 additions & 1 deletion packages/dotto.x/create-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export const createStore = (initial = {}) => {
let store = {
lc: 0,
set(path, value) {
set(state, concat(DATA, path), value)
let res = set(state, concat(DATA, path), value)
this._emit(path)
return res
},
get(path) {
return get(state, concat(DATA, path))
Expand Down
2 changes: 2 additions & 0 deletions packages/dotto.x/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export * from './computed'
export { mount } from './mount'

export { task, allTasks } from './task'
export { ResolveType } from './utils/get'

export { effect } from './effect'
export { bind, BindedStore } from './bind'
1 change: 1 addition & 0 deletions packages/dotto.x/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { mount } from './mount'
export { task, allTasks } from './task'

export { effect } from './effect'
export { bind } from './bind'
15 changes: 1 addition & 14 deletions packages/dotto.x/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
"size": "size-limit",
"deploy": "npx clean-publish"
},
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"react-dom": {
"optional": true
}
},
"clean-publish": {
"files": [
"logo.png",
Expand Down Expand Up @@ -120,7 +108,7 @@
],
"exports": {
".": "./index.js",
"./react": "./react/index.js",
"./lifecycle": "./lifecycle/index.js",
"./package.json": "./package.json"
},
"engines": {
Expand All @@ -146,7 +134,6 @@
"eslint-plugin-unicorn": "^33.0.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"react": "^17.0.2",
"size-limit": "^5.0.1",
"ts-jest": "^27.0.3",
"typescript": "^4.3.4",
Expand Down
3 changes: 3 additions & 0 deletions packages/dotto.x/query/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ export function query<Data, T extends Object>(
}
) => void
) => () => void
get(): {
[K in keyof T]: ResolveType<Data, T[K]>
}
}
18 changes: 10 additions & 8 deletions packages/dotto.x/query/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const AssertType = <T>(expect: [T] extends [never] ? never : T): T => expect

describe('query:', () => {
it('base', () => {
expect.assertions(12)
expect.assertions(13)

let testingStore = createStore<{
some: { user: { name?: string; age?: number; location?: string } }
Expand All @@ -27,13 +27,13 @@ describe('query:', () => {
location: 'some.user.location'
} as const

let unbind = query(testingStore, select).subscribe(
({ name, age, location }) => {
expect(AssertType<Name>(name)).toEqual(predict.name)
expect(AssertType<Age>(age)).toEqual(predict.age)
expect(AssertType<Location>(location)).toEqual(predict.location)
}
)
let myOwnQuery = query(testingStore, select)

let unbind = myOwnQuery.subscribe(({ name, age, location }) => {
expect(AssertType<Name>(name)).toEqual(predict.name)
expect(AssertType<Age>(age)).toEqual(predict.age)
expect(AssertType<Location>(location)).toEqual(predict.location)
})

predict = {
name: 'John',
Expand All @@ -54,6 +54,8 @@ describe('query:', () => {
}
testingStore.set('some.user.location', 'USA')

expect(myOwnQuery.get()).toEqual(predict)

unbind()
})
})
5 changes: 2 additions & 3 deletions packages/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export const fetch = async (deps, url, init) => {
return result
}

export const fetchJson = (deps, url, init) => {
return task(async () => {
export const fetchJson = (deps, url, init) =>
task(async () => {
let fetchResult = await fetch(deps, url, init)
return fetchResult.json()
})
}
3 changes: 1 addition & 2 deletions packages/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Eddort <webisforce@gmail.com>",
"license": "MIT",
"sideEffects": false,
"privete": false,
"private": false,
"type": "module",
"types": "./index.d.ts",
"scripts": {
Expand Down Expand Up @@ -122,7 +122,6 @@
"eslint-plugin-unicorn": "^33.0.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"react": "^17.0.2",
"size-limit": "^5.0.1",
"ts-jest": "^27.0.3",
"typescript": "^4.3.4",
Expand Down
10 changes: 10 additions & 0 deletions packages/react/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
yarn-error.log
yarn.lock

coverage/
**/types.ts
**/*.test.ts
tsconfig.json
test/
ideas
wip
Empty file added packages/react/README.md
Empty file.
1 change: 1 addition & 0 deletions packages/react/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useSelector } from './useSelector'
1 change: 1 addition & 0 deletions packages/react/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useSelector } from './useSelector'
133 changes: 133 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"name": "@dotto.x/react",
"version": "0.2.3",
"description": "A tiny state manager",
"main": "index.js",
"repository": "https://github.com/dottostack/dotto.x",
"author": "Eddort <webisforce@gmail.com>",
"license": "MIT",
"sideEffects": false,
"private": true,
"type": "module",
"types": "./index.d.ts",
"scripts": {
"test": "echo 'todo'",
"test:wip": "node --experimental-vm-modules ../../node_modules/.bin/jest --runInBand --coverage && eslint . && check-dts && yarn size && yaspeller *.md",
"test:watch": "node --experimental-vm-modules ../../node_modules/.bin/jest --runInBand --watch",
"size": "size-limit",
"deploy": "npx clean-publish"
},
"peerDependencies": {
"dotto.x": "0.2.3",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"clean-publish": {
"files": [
"logo.png",
"ideas.md"
],
"packageManager": "npm",
"access": "public"
},
"prettier": {
"arrowParens": "avoid",
"jsxSingleQuote": false,
"quoteProps": "consistent",
"semi": false,
"singleQuote": true,
"trailingComma": "none"
},
"jest": {
"modulePathIgnorePatterns": [
"wip"
],
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
},
"testEnvironment": "jsdom",
"coverageThreshold": {
"global": {
"statements": 100
}
}
},
"eslintConfig": {
"extends": "@logux/eslint-config/esm",
"rules": {
"@typescript-eslint/unified-signatures": "off",
"@typescript-eslint/no-explicit-any": "off",
"symbol-description": "off",
"consistent-return": "off",
"camelcase": "off",
"import/extensions": "off"
},
"globals": {
"jsdom": false
}
},
"yaspeller": {
"lang": "en",
"ignoreCapitalization": true,
"ignoreText": [
" \\(by [^)]+\\).",
"\\d+\\.\\d+ “[^”]+”"
],
"excludeFiles": [
".git",
"node_modules",
"ideas.md"
],
"dictionary": [
"dotto",
"Redux",
"devtools",
"splited",
"JS",
"Shakable",
"gzipped",
"WIP"
]
},
"size-limit": [
{
"name": "all",
"path": "./index.js"
}
],
"exports": {
".": "./index.js"
},
"engines": {
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
},
"devDependencies": {
"@logux/eslint-config": "^45.4.4",
"@size-limit/preset-small-lib": "^5.0.1",
"@types/jest": "^26.0.24",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"check-dts": "^0.5.3",
"dotto.x": "^0.2.3",
"eslint": "^7.29.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-es5": "^1.5.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-let": "^1.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-unicorn": "^33.0.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"size-limit": "^5.0.1",
"ts-jest": "^27.0.3",
"typescript": "^4.3.4",
"yaspeller": "^7.0.0"
}
}
13 changes: 13 additions & 0 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"strict": true,
"noEmit": true,
"jsx": "react"
}
}
6 changes: 6 additions & 0 deletions packages/react/useSelector/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DotXStore, ResolveType } from 'dotto.x'

export function useSelector<Data, Selector extends string>(
store: DotXStore<Data>,
selector: Selector
): ResolveType<Data, Selector>
Loading

0 comments on commit 2d59b2b

Please sign in to comment.