@tanstack/react-store
Advanced tools
Comparing version 0.0.1-beta.121 to 0.0.1-beta.134
@@ -15,3 +15,2 @@ /** | ||
require('react'); | ||
var withSelector = require('use-sync-external-store/shim/with-selector'); | ||
@@ -21,45 +20,3 @@ var store = require('@tanstack/store'); | ||
function useStore(store, selector = d => d) { | ||
// const isMountedRef = React.useRef(false) | ||
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({ | ||
// ref: selector(store.state), | ||
// })) | ||
// if (!shallow(selector(store.state), state.ref)) { | ||
// setState(() => ({ ref: selector(store.state) })) | ||
// } | ||
// useLayoutEffect(() => { | ||
// console.log('effect') | ||
// const cb = () => { | ||
// const next = selector(store.state) | ||
// console.log('onsub') | ||
// if (!shallow(next, state.ref)) { | ||
// console.log('set') | ||
// setState(() => ({ ref: selector(store.state) })) | ||
// } | ||
// } | ||
// return store.subscribe(cb) | ||
// }, []) | ||
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow); | ||
// if (!isMountedRef.current) { | ||
// state.ref = slice | ||
// } | ||
// if (!shallow(slice, state.ref)) { | ||
// setState({ ref: slice }) | ||
// } | ||
// React.useEffect(() => { | ||
// isMountedRef.current = true | ||
// return () => { | ||
// isMountedRef.current = false | ||
// } | ||
// }, []) | ||
// return state.ref | ||
return slice; | ||
@@ -66,0 +23,0 @@ } |
@@ -11,3 +11,2 @@ /** | ||
*/ | ||
import 'react'; | ||
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'; | ||
@@ -17,45 +16,3 @@ export * from '@tanstack/store'; | ||
function useStore(store, selector = d => d) { | ||
// const isMountedRef = React.useRef(false) | ||
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({ | ||
// ref: selector(store.state), | ||
// })) | ||
// if (!shallow(selector(store.state), state.ref)) { | ||
// setState(() => ({ ref: selector(store.state) })) | ||
// } | ||
// useLayoutEffect(() => { | ||
// console.log('effect') | ||
// const cb = () => { | ||
// const next = selector(store.state) | ||
// console.log('onsub') | ||
// if (!shallow(next, state.ref)) { | ||
// console.log('set') | ||
// setState(() => ({ ref: selector(store.state) })) | ||
// } | ||
// } | ||
// return store.subscribe(cb) | ||
// }, []) | ||
const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow); | ||
// if (!isMountedRef.current) { | ||
// state.ref = slice | ||
// } | ||
// if (!shallow(slice, state.ref)) { | ||
// setState({ ref: slice }) | ||
// } | ||
// React.useEffect(() => { | ||
// isMountedRef.current = true | ||
// return () => { | ||
// isMountedRef.current = false | ||
// } | ||
// }, []) | ||
// return state.ref | ||
return slice; | ||
@@ -62,0 +19,0 @@ } |
@@ -14,7 +14,7 @@ { | ||
"name": "store/build/esm/index.js", | ||
"uid": "0fb9-11" | ||
"uid": "2231-10" | ||
}, | ||
{ | ||
"name": "react-store/src/index.tsx", | ||
"uid": "0fb9-13" | ||
"uid": "2231-12" | ||
} | ||
@@ -29,20 +29,20 @@ ] | ||
"nodeParts": { | ||
"0fb9-11": { | ||
"renderedLength": 1359, | ||
"gzipLength": 537, | ||
"2231-10": { | ||
"renderedLength": 1843, | ||
"gzipLength": 644, | ||
"brotliLength": 0, | ||
"mainUid": "0fb9-10" | ||
"mainUid": "2231-9" | ||
}, | ||
"0fb9-13": { | ||
"renderedLength": 1778, | ||
"gzipLength": 607, | ||
"2231-12": { | ||
"renderedLength": 754, | ||
"gzipLength": 343, | ||
"brotliLength": 0, | ||
"mainUid": "0fb9-12" | ||
"mainUid": "2231-11" | ||
} | ||
}, | ||
"nodeMetas": { | ||
"0fb9-10": { | ||
"2231-9": { | ||
"id": "/packages/store/build/esm/index.js", | ||
"moduleParts": { | ||
"index.production.js": "0fb9-11" | ||
"index.production.js": "2231-10" | ||
}, | ||
@@ -52,20 +52,17 @@ "imported": [], | ||
{ | ||
"uid": "0fb9-12" | ||
"uid": "2231-11" | ||
} | ||
] | ||
}, | ||
"0fb9-12": { | ||
"2231-11": { | ||
"id": "/packages/react-store/src/index.tsx", | ||
"moduleParts": { | ||
"index.production.js": "0fb9-13" | ||
"index.production.js": "2231-12" | ||
}, | ||
"imported": [ | ||
{ | ||
"uid": "0fb9-14" | ||
"uid": "2231-13" | ||
}, | ||
{ | ||
"uid": "0fb9-15" | ||
}, | ||
{ | ||
"uid": "0fb9-10" | ||
"uid": "2231-9" | ||
} | ||
@@ -76,14 +73,3 @@ ], | ||
}, | ||
"0fb9-14": { | ||
"id": "react", | ||
"moduleParts": {}, | ||
"imported": [], | ||
"importedBy": [ | ||
{ | ||
"uid": "0fb9-12" | ||
} | ||
], | ||
"isExternal": true | ||
}, | ||
"0fb9-15": { | ||
"2231-13": { | ||
"id": "use-sync-external-store/shim/with-selector", | ||
@@ -94,3 +80,3 @@ "moduleParts": {}, | ||
{ | ||
"uid": "0fb9-12" | ||
"uid": "2231-11" | ||
} | ||
@@ -97,0 +83,0 @@ ], |
@@ -12,6 +12,6 @@ /** | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('use-sync-external-store/shim/with-selector')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react', 'use-sync-external-store/shim/with-selector'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactLoaders = {}, global.React, global.withSelector)); | ||
})(this, (function (exports, React, withSelector) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('use-sync-external-store/shim/with-selector')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'use-sync-external-store/shim/with-selector'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactLoaders = {}, global.withSelector)); | ||
})(this, (function (exports, withSelector) { 'use strict'; | ||
@@ -32,2 +32,3 @@ /** | ||
_flushing = 0; | ||
_nextPriority = null; | ||
constructor(initialState, options) { | ||
@@ -45,8 +46,18 @@ this.state = initialState; | ||
}; | ||
setState = updater => { | ||
setState = (updater, opts) => { | ||
const previous = this.state; | ||
this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous); | ||
const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high'; | ||
if (this._nextPriority === null) { | ||
this._nextPriority = priority; | ||
} else if (this._nextPriority === 'high') { | ||
this._nextPriority = priority; | ||
} else { | ||
this._nextPriority = this.options?.defaultPriority ?? 'high'; | ||
} | ||
// Always run onUpdate, regardless of batching | ||
this.options?.onUpdate?.(); | ||
this.options?.onUpdate?.({ | ||
priority: this._nextPriority | ||
}); | ||
@@ -61,3 +72,5 @@ // Attempt to flush | ||
if (this._flushing !== flushId) return; | ||
listener(); | ||
listener({ | ||
priority: this._nextPriority ?? 'high' | ||
}); | ||
}); | ||
@@ -75,45 +88,3 @@ }; | ||
function useStore(store, selector = d => d) { | ||
// const isMountedRef = React.useRef(false) | ||
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({ | ||
// ref: selector(store.state), | ||
// })) | ||
// if (!shallow(selector(store.state), state.ref)) { | ||
// setState(() => ({ ref: selector(store.state) })) | ||
// } | ||
// useLayoutEffect(() => { | ||
// console.log('effect') | ||
// const cb = () => { | ||
// const next = selector(store.state) | ||
// console.log('onsub') | ||
// if (!shallow(next, state.ref)) { | ||
// console.log('set') | ||
// setState(() => ({ ref: selector(store.state) })) | ||
// } | ||
// } | ||
// return store.subscribe(cb) | ||
// }, []) | ||
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow); | ||
// if (!isMountedRef.current) { | ||
// state.ref = slice | ||
// } | ||
// if (!shallow(slice, state.ref)) { | ||
// setState({ ref: slice }) | ||
// } | ||
// React.useEffect(() => { | ||
// isMountedRef.current = true | ||
// return () => { | ||
// isMountedRef.current = false | ||
// } | ||
// }, []) | ||
// return state.ref | ||
return slice; | ||
@@ -120,0 +91,0 @@ } |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","react","use-sync-external-store/shim/with-selector"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactLoaders={},t.React,t.withSelector)}(this,(function(t,e,s){"use strict"; | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactLoaders={},t.withSelector)}(this,(function(t,e){"use strict"; | ||
/** | ||
@@ -22,3 +22,3 @@ * @tanstack/store/src/index.ts | ||
* @license MIT | ||
*/function i(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const s=Object.keys(t);if(s.length!==Object.keys(e).length)return!1;for(let i=0;i<s.length;i++)if(!Object.prototype.hasOwnProperty.call(e,s[i])||!Object.is(t[s[i]],e[s[i]]))return!1;return!0}t.Store=class{listeners=new Set;_batching=!1;_flushing=0;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=t=>{const e=this.state;this.state=this.options?.updateFn?this.options.updateFn(e)(t):t(e),this.options?.onUpdate?.(),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e()}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}},t.shallow=i,t.useStore=function(t,e=(t=>t)){return s.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),e,i)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
*/function i(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const i=Object.keys(t);if(i.length!==Object.keys(e).length)return!1;for(let s=0;s<i.length;s++)if(!Object.prototype.hasOwnProperty.call(e,i[s])||!Object.is(t[i[s]],e[i[s]]))return!1;return!0}t.Store=class{listeners=new Set;_batching=!1;_flushing=0;_nextPriority=null;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=(t,e)=>{const i=this.state;this.state=this.options?.updateFn?this.options.updateFn(i)(t):t(i);const s=e?.priority??this.options?.defaultPriority??"high";null===this._nextPriority||"high"===this._nextPriority?this._nextPriority=s:this._nextPriority=this.options?.defaultPriority??"high",this.options?.onUpdate?.({priority:this._nextPriority}),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e({priority:this._nextPriority??"high"})}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}},t.shallow=i,t.useStore=function(t,s=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),s,i)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/react-store", | ||
"author": "Tanner Linsley", | ||
"version": "0.0.1-beta.121", | ||
"version": "0.0.1-beta.134", | ||
"license": "MIT", | ||
@@ -39,3 +39,3 @@ "repository": "tanstack/react-store", | ||
"use-sync-external-store": "^1.2.0", | ||
"@tanstack/store": "0.0.1-beta.121" | ||
"@tanstack/store": "0.0.1-beta.134" | ||
}, | ||
@@ -42,0 +42,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166923
368
+ Added@tanstack/store@0.0.1-beta.134(transitive)
- Removed@tanstack/store@0.0.1-beta.121(transitive)