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

Zustand 2.x // Ensure order of subscribers #65

Merged
merged 12 commits into from Oct 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 12 additions & 50 deletions .size-snapshot.json
@@ -1,8 +1,8 @@
{
"dist/index.js": {
"bundled": 3090,
"minified": 1286,
"gzipped": 669,
"bundled": 3774,
"minified": 1232,
"gzipped": 589,
"treeshaked": {
"rollup": {
"code": 14,
Expand All @@ -14,61 +14,23 @@
}
},
"dist/index.cjs.js": {
"bundled": 3830,
"minified": 1533,
"gzipped": 755
"bundled": 4707,
"minified": 1493,
"gzipped": 678
},
"dist/index.iife.js": {
"bundled": 4015,
"minified": 1369,
"gzipped": 688
"bundled": 4934,
"minified": 1329,
"gzipped": 619
},
"dist/shallow.js": {
"bundled": 559,
"minified": 350,
"gzipped": 217,
"treeshaked": {
"rollup": {
"code": 0,
"import_statements": 0
},
"webpack": {
"code": 951
}
}
},
"dist/shallow.cjs.js": {
"bundled": 646,
"minified": 425,
"gzipped": 256
},
"dist/shallow.iife.js": {
"bundled": 688,
"minified": 378,
"gzipped": 236
},
"dist/middleware.js": {
"bundled": 1492,
"minified": 760,
"gzipped": 426,
"treeshaked": {
"rollup": {
"code": 0,
"import_statements": 0
},
"webpack": {
"code": 951
}
}
},
"dist/middleware.cjs.js": {
"bundled": 2185,
"minified": 1176,
"gzipped": 598
},
"dist/middleware.iife.js": {
"bundled": 2324,
"minified": 1095,
"gzipped": 567
"bundled": 2126,
"minified": 1205,
"gzipped": 621
}
}
22 changes: 11 additions & 11 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "zustand",
"private": true,
"version": "1.0.7",
"version": "2.0.0",
"description": "🐻 Bear necessities for state management in React",
"main": "index.cjs.js",
"module": "index.js",
Expand Down Expand Up @@ -80,29 +80,29 @@
]
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/core": "^7.6.2",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/plugin-transform-typescript": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@testing-library/react": "^9.1.4",
"@babel/preset-env": "^7.6.2",
"@testing-library/react": "^9.3.0",
"@types/jest": "^24.0.18",
"@types/react": "^16.9.2",
"@types/react": "^16.9.5",
"copyfiles": "^2.1.1",
"husky": "^3.0.5",
"husky": "^3.0.8",
"jest": "^24.9.0",
"json": "^9.0.6",
"lint-staged": "^9.2.5",
"lint-staged": "^9.4.1",
"prettier": "^1.18.2",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"rimraf": "^3.0.0",
"rollup": "^1.21.2",
"rollup": "^1.23.1",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-size-snapshot": "^0.10.0",
"rollup-plugin-typescript2": "^0.24.1",
"rollup-plugin-typescript2": "^0.24.3",
"typescript": "^3.6.3"
},
"peerDependencies": {
Expand Down
98 changes: 52 additions & 46 deletions rollup.config.js
Expand Up @@ -5,7 +5,7 @@ import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
import typescript from 'rollup-plugin-typescript2'

const getBabelRc = require('./.babelrc.js')
const root = process.platform === 'win32' ? path.resolve('/') : '/'
const { root } = path.parse(process.cwd())
const external = id => !id.startsWith('.') && !id.startsWith(root)
const extensions = ['.js', '.ts', '.tsx']
const getBabelOptions = targets => ({
Expand All @@ -14,54 +14,60 @@ const getBabelOptions = targets => ({
...getBabelRc({ env: v => v === 'production' }, targets),
})

function createConfig(entry, out, name) {
return [
{
input: entry,
output: { file: `dist/${out}.js`, format: 'esm' },
external,
plugins: [
typescript(),
babel(getBabelOptions('node 8')),
sizeSnapshot(),
resolve({ extensions }),
],
},
{
input: entry,
output: { file: `dist/${out}.cjs.js`, format: 'cjs', exports: 'named' },
external,
plugins: [
typescript(),
babel(getBabelOptions('ie 11')),
sizeSnapshot(),
resolve({ extensions }),
],
},
{
input: entry,
output: {
file: `dist/${out}.iife.js`,
format: 'iife',
exports: 'named',
name,
globals: {
react: 'React',
},
function createESMConfig(input, output) {
return {
input,
output: { file: output, format: 'esm' },
external,
plugins: [
typescript(),
babel(getBabelOptions('node 8')),
sizeSnapshot(),
resolve({ extensions }),
],
}
}

function createCommonJSConfig(input, output) {
return {
input,
output: { file: output, format: 'cjs', exports: 'named' },
external,
plugins: [
typescript(),
babel(getBabelOptions('ie 11')),
sizeSnapshot(),
resolve({ extensions }),
],
}
}

function createIIFEConfig(input, output, globalName) {
return {
input,
output: {
file: output,
format: 'iife',
exports: 'named',
name: globalName,
globals: {
react: 'React',
},
external,
plugins: [
typescript(),
babel(getBabelOptions('ie 11')),
sizeSnapshot(),
resolve({ extensions }),
],
},
]
external,
plugins: [
typescript(),
babel(getBabelOptions('ie 11')),
sizeSnapshot(),
resolve({ extensions }),
],
}
}

export default [
...createConfig('src/index.ts', 'index', 'zustand'),
...createConfig('src/shallow.ts', 'shallow', 'shallow'),
...createConfig('src/middleware.ts', 'middleware', 'middleware'),
createESMConfig('src/index.ts', 'dist/index.js'),
createCommonJSConfig('src/index.ts', 'dist/index.cjs.js'),
createIIFEConfig('src/index.ts', 'dist/index.iife.js', 'zustand'),
createCommonJSConfig('src/shallow.ts', 'dist/shallow.js'),
createCommonJSConfig('src/middleware.ts', 'dist/middleware.js'),
]