Skip to content

Commit

Permalink
fix: state issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jul 3, 2023
1 parent 315854c commit 20d26ca
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 47 deletions.
8 changes: 8 additions & 0 deletions examples/react/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@
"devDependencies": {
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8"
},
"pnpm": {
"overrides": {
"@tanstack/router": "workspace:*",
"@tanstack/react-actions": "workspace:*",
"@tanstack/react-loaders": "workspace:*",
"@tanstack/router-devtools": "workspace:*"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test:ci": "vitest run",
"test:dev": "vitest watch",
"build": "nx run-many --target=build --projects=@tanstack/* --exclude=@tanstack/react-start",
"watch": "concurrently --kill-others \"rollup --config rollup.config.js -w\" \"tsc -b --watch\"",
"watch": "concurrently --no-color --prefix \"watch\" --kill-others --raw \"rollup --config rollup.config.js -w\" \"tsc -b --watch --preserveWatchOutput\"",
"dev": "pnpm watch",
"prettier": "prettier \"packages/*/{src/**,examples/**/src/**}.{md,js,jsx,ts,tsx,json}\" --write",
"visualize": "pnpm -rc --parallel exec open build/stats-html.html",
Expand Down
7 changes: 4 additions & 3 deletions packages/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export class Store<
constructor(initialState: TState, options?: StoreOptions<TState, TUpdater>) {
this.state = initialState
this.options = options
if (this.options?.onUpdate) {
this.subscribe(this.options?.onUpdate)
}
}

subscribe = (listener: Listener) => {
Expand All @@ -47,6 +44,10 @@ export class Store<
? this.options.updateFn(previous)(updater)
: (updater as any)(previous)

// Always run onUpdate, regardless of batching
this.options?.onUpdate?.()

// Attempt to flush
this._flush()
}

Expand Down
93 changes: 59 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require('ts-node').register({
compilerOptions: {
esModuleInterop: true,
},
})

module.exports = require('./rollup.config.ts')
13 changes: 4 additions & 9 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,9 @@ const babelPlugin = babel({
extensions: ['.ts', '.tsx'],
})

export function createRollupConfig(packageName: string): () => RollupOptions[] {
const pkg = packages.find((p) => p.name === packageName)
if (!pkg) {
throw new Error(
`Package ${packageName} not found - check the package name given in your package's rollup.config.js file.`,
)
}
return () =>
buildConfigs({
export default function rollup(options: RollupOptions): RollupOptions[] {
return packages.flatMap((pkg) => {
return buildConfigs({
name: pkg.packageDir,
packageDir: `packages/${pkg.packageDir}`,
jsName: pkg.jsName,
Expand All @@ -56,6 +50,7 @@ export function createRollupConfig(packageName: string): () => RollupOptions[] {
cjs: pkg.cjs ?? true,
umd: pkg.umd ?? true,
})
})
}

function buildConfigs(opts: {
Expand Down

0 comments on commit 20d26ca

Please sign in to comment.