cogsbox-state 0.5.463 → 0.5.464

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-state",
3
- "version": "0.5.463",
3
+ "version": "0.5.464",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/CogsState.tsx CHANGED
@@ -642,7 +642,6 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
642
642
  stateKey: StateKey,
643
643
  options?: Prettify<OptionsType<(typeof statePart)[StateKey]>>
644
644
  ) => {
645
- console.time('useCogsState');
646
645
  const [componentId] = useState(options?.componentId ?? uuidv4());
647
646
 
648
647
  setOptions({
@@ -657,8 +656,6 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
657
656
  ? options.modifyState(thiState)
658
657
  : thiState;
659
658
 
660
- console.timeEnd('useCogsState');
661
-
662
659
  const updater = useCogsStateFn<(typeof statePart)[StateKey]>(partialState, {
663
660
  stateKey: stateKey as string,
664
661
  syncUpdate: options?.syncUpdate,
@@ -996,7 +993,6 @@ export function useCogsStateFn<TStateObject extends unknown>(
996
993
  syncOptions?: SyncOptionsType<any>;
997
994
  } & OptionsType<TStateObject> = {}
998
995
  ) {
999
- console.time('useCogsStateFn top');
1000
996
  const [reactiveForce, forceUpdate] = useState({}); //this is the key to reactivity
1001
997
  const { sessionId } = useCogsConfig();
1002
998
  let noStateKey = stateKey ? false : true;
@@ -1312,22 +1308,18 @@ export function useCogsStateFn<TStateObject extends unknown>(
1312
1308
  }, []);
1313
1309
 
1314
1310
  const syncApiRef = useRef<SyncApi | null>(null);
1315
- console.timeEnd('useCogsStateFn top');
1316
1311
 
1317
1312
  const effectiveSetState = (
1318
1313
  newStateOrFunction: UpdateArg<TStateObject> | InsertParams<TStateObject>,
1319
1314
  path: string[],
1320
1315
  updateObj: UpdateOptions
1321
1316
  ) => {
1322
- console.time('top of effectiveSetState');
1323
1317
  const fullPath = [thisKey, ...path].join('.');
1324
1318
  const store = getGlobalStore.getState();
1325
1319
 
1326
1320
  const shadowMeta = store.getShadowMetadata(thisKey, path);
1327
1321
  const nestedShadowValue = store.getShadowValue(fullPath) as TStateObject;
1328
- console.timeEnd('top of effectiveSetState');
1329
1322
 
1330
- console.time('top of payload');
1331
1323
  const payload = (
1332
1324
  updateObj.updateType === 'insert' && isFunction(newStateOrFunction)
1333
1325
  ? newStateOrFunction({ state: nestedShadowValue, uuid: uuidv4() })
@@ -1347,9 +1339,7 @@ export function useCogsStateFn<TStateObject extends unknown>(
1347
1339
  oldValue: nestedShadowValue,
1348
1340
  newValue: payload,
1349
1341
  } satisfies UpdateTypeDetail;
1350
- console.timeEnd('top of payload');
1351
1342
 
1352
- console.time('switch in effectiveSetState');
1353
1343
  // Perform the update
1354
1344
  switch (updateObj.updateType) {
1355
1345
  case 'insert': {
@@ -1379,9 +1369,8 @@ export function useCogsStateFn<TStateObject extends unknown>(
1379
1369
  break;
1380
1370
  }
1381
1371
  }
1382
- console.timeEnd('switch in effectiveSetState');
1372
+
1383
1373
  const shouldSync = updateObj.sync !== false;
1384
- console.time('signals');
1385
1374
 
1386
1375
  if (shouldSync && syncApiRef.current && syncApiRef.current.connected) {
1387
1376
  syncApiRef.current.updateState({ operation: newUpdate });
@@ -1552,9 +1541,7 @@ export function useCogsStateFn<TStateObject extends unknown>(
1552
1541
  });
1553
1542
  }
1554
1543
  }
1555
- console.timeEnd('signals');
1556
1544
 
1557
- console.time('notify');
1558
1545
  const rootMeta = store.getShadowMetadata(thisKey, []);
1559
1546
  const notifiedComponents = new Set<string>();
1560
1547
 
@@ -1741,8 +1728,7 @@ export function useCogsStateFn<TStateObject extends unknown>(
1741
1728
  }
1742
1729
  });
1743
1730
  notifiedComponents.clear();
1744
- console.timeEnd('notify');
1745
- console.time('end stuff');
1731
+
1746
1732
  addStateLog(thisKey, newUpdate);
1747
1733
 
1748
1734
  saveToLocalStorage(
@@ -1757,7 +1743,6 @@ export function useCogsStateFn<TStateObject extends unknown>(
1757
1743
  update: newUpdate,
1758
1744
  });
1759
1745
  }
1760
- console.timeEnd('end stuff');
1761
1746
  };
1762
1747
 
1763
1748
  if (!getGlobalStore.getState().initialStateGlobal[thisKey]) {
@@ -1765,14 +1750,13 @@ export function useCogsStateFn<TStateObject extends unknown>(
1765
1750
  }
1766
1751
 
1767
1752
  const updaterFinal = useMemo(() => {
1768
- console.time('createProxyHandler');
1769
1753
  const handler = createProxyHandler<TStateObject>(
1770
1754
  thisKey,
1771
1755
  effectiveSetState,
1772
1756
  componentIdRef.current,
1773
1757
  sessionId
1774
1758
  );
1775
- console.timeEnd('createProxyHandler'); // <--- AND THIS
1759
+
1776
1760
  return handler;
1777
1761
  }, [thisKey, sessionId]);
1778
1762
 
@@ -1936,7 +1920,6 @@ function createProxyHandler<T>(
1936
1920
  ): StateObject<T> {
1937
1921
  const proxyCache = new Map<string, any>();
1938
1922
  let stateVersion = 0;
1939
- console.time('rebuildStateShape Outer');
1940
1923
 
1941
1924
  let recursionTimerName: string | null = null;
1942
1925
 
@@ -1949,7 +1932,6 @@ function createProxyHandler<T>(
1949
1932
  componentId: string;
1950
1933
  meta?: MetaData;
1951
1934
  }): any {
1952
- console.time('rebuildStateShape Inner');
1953
1935
  const derivationSignature = meta
1954
1936
  ? JSON.stringify(meta.validIds || meta.transforms)
1955
1937
  : '';
@@ -1975,16 +1957,7 @@ function createProxyHandler<T>(
1975
1957
  // This is a placeholder for the proxy.
1976
1958
 
1977
1959
  const handler = {
1978
- apply(target: any, thisArg: any, args: any[]) {
1979
- //return getGlobalStore().getShadowValue(stateKey, path);
1980
- },
1981
-
1982
1960
  get(target: any, prop: string) {
1983
- if (path.length === 0) {
1984
- // Create a unique name for this specific timer instance
1985
- recursionTimerName = `Recursion-${Math.random()}`;
1986
- console.time(recursionTimerName);
1987
- }
1988
1961
  if (prop === '_rebuildStateShape') {
1989
1962
  return rebuildStateShape;
1990
1963
  }
@@ -3608,11 +3581,6 @@ function createProxyHandler<T>(
3608
3581
  if (prop === '_stateKey') return stateKey;
3609
3582
  if (prop === '_path') return path;
3610
3583
  if (prop === 'update') {
3611
- if (recursionTimerName) {
3612
- console.timeEnd(recursionTimerName);
3613
- recursionTimerName = null;
3614
- }
3615
-
3616
3584
  return (payload: UpdateArg<T>) => {
3617
3585
  // Check if we're in a React event handler
3618
3586
  const error = new Error();
@@ -3669,10 +3637,7 @@ function createProxyHandler<T>(
3669
3637
  existing.push(payload);
3670
3638
  updateBatchQueue.set(batchKey, existing);
3671
3639
  } else {
3672
- // NOT in React event - execute immediately
3673
- console.time('update inner');
3674
3640
  effectiveSetState(payload as any, path, { updateType: 'update' });
3675
- console.timeEnd('update inner');
3676
3641
  }
3677
3642
 
3678
3643
  return {
@@ -3740,10 +3705,9 @@ function createProxyHandler<T>(
3740
3705
 
3741
3706
  const proxyInstance = new Proxy(baseFunction, handler);
3742
3707
  proxyCache.set(cacheKey, proxyInstance);
3743
- console.timeEnd('rebuildStateShape Inner');
3708
+
3744
3709
  return proxyInstance;
3745
3710
  }
3746
- console.timeEnd('rebuildStateShape Outer');
3747
3711
 
3748
3712
  const baseObj = {
3749
3713
  revertToInitialState: (obj?: { validationKey?: string }) => {