@oimdb/core 1.2.0 → 1.2.2
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/README.md +16 -6
- package/dist/index.cjs +13 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -371,28 +371,38 @@ const teamUsers = useSelectEntitiesByPks(users, userIds);
|
|
|
371
371
|
Migrate from Redux to OIMDB gradually or use both systems side-by-side with automatic two-way synchronization:
|
|
372
372
|
|
|
373
373
|
```typescript
|
|
374
|
-
import {
|
|
375
|
-
import { createStore, combineReducers } from 'redux';
|
|
374
|
+
import { OIMDBAdapter } from '@oimdb/redux-adapter';
|
|
375
|
+
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
376
|
+
|
|
377
|
+
// Create Redux adapter
|
|
378
|
+
const adapter = new OIMDBAdapter(queue);
|
|
376
379
|
|
|
377
380
|
// Create Redux reducer from OIMDB collection
|
|
378
|
-
const
|
|
379
|
-
|
|
381
|
+
const usersReducer = adapter.createCollectionReducer(users);
|
|
382
|
+
|
|
383
|
+
// Create middleware for automatic flushing
|
|
384
|
+
const middleware = adapter.createMiddleware();
|
|
380
385
|
|
|
381
386
|
// Use in existing Redux store
|
|
382
387
|
const store = createStore(
|
|
383
388
|
combineReducers({
|
|
384
389
|
users: usersReducer, // OIMDB-backed reducer
|
|
385
390
|
ui: uiReducer, // Existing Redux reducer
|
|
386
|
-
})
|
|
391
|
+
}),
|
|
392
|
+
applyMiddleware(middleware)
|
|
387
393
|
);
|
|
388
394
|
|
|
395
|
+
adapter.setStore(store);
|
|
396
|
+
|
|
389
397
|
// OIMDB changes automatically sync to Redux
|
|
390
|
-
// Redux actions
|
|
398
|
+
// Redux actions automatically sync back to OIMDB with child reducers
|
|
399
|
+
// Middleware automatically flushes queue after each action - no manual flush needed!
|
|
391
400
|
```
|
|
392
401
|
|
|
393
402
|
**Key Benefits:**
|
|
394
403
|
- **🔄 Gradual Migration**: Migrate one collection at a time without breaking changes
|
|
395
404
|
- **🔄 Two-Way Sync**: Automatic synchronization between OIMDB and Redux
|
|
405
|
+
- **⚡ Automatic Flushing**: Middleware automatically processes events after Redux actions
|
|
396
406
|
- **📦 Production Ready**: Battle-tested adapter optimized for large datasets
|
|
397
407
|
- **🎯 Flexible**: Works with any Redux state structure via custom mappers
|
|
398
408
|
|
package/dist/index.cjs
CHANGED
|
@@ -765,6 +765,10 @@ var OIMCollection = class {
|
|
|
765
765
|
getManyByPks(pks) {
|
|
766
766
|
return this.store.getManyByPks(pks);
|
|
767
767
|
}
|
|
768
|
+
upsertOneByPk(pk, entity) {
|
|
769
|
+
this.upsertOneWithoutNotificationsByPk(pk, entity);
|
|
770
|
+
this.emitter.emit(0 /* UPDATE */, { pks: [pk] });
|
|
771
|
+
}
|
|
768
772
|
upsertOne(entity) {
|
|
769
773
|
const pk = this.upsertOneWithoutNotifications(entity);
|
|
770
774
|
this.emitter.emit(0 /* UPDATE */, { pks: [pk] });
|
|
@@ -808,6 +812,15 @@ var OIMCollection = class {
|
|
|
808
812
|
}
|
|
809
813
|
upsertOneWithoutNotifications(entity) {
|
|
810
814
|
const pk = this.selectPk(entity);
|
|
815
|
+
this.upsertOneWithoutNotificationsByPk(pk, entity);
|
|
816
|
+
return pk;
|
|
817
|
+
}
|
|
818
|
+
upsertOneWithoutNotificationsByPk(pk, entity) {
|
|
819
|
+
if (!pk) {
|
|
820
|
+
throw new Error(
|
|
821
|
+
`[OIMCollection]: PK is required to upsert an entity ${JSON.stringify(entity)}`
|
|
822
|
+
);
|
|
823
|
+
}
|
|
811
824
|
const existingEntity = this.store.getOneByPk(pk);
|
|
812
825
|
if (existingEntity) {
|
|
813
826
|
this.store.setOneByPk(
|
|
@@ -817,7 +830,6 @@ var OIMCollection = class {
|
|
|
817
830
|
} else {
|
|
818
831
|
this.store.setOneByPk(pk, entity);
|
|
819
832
|
}
|
|
820
|
-
return pk;
|
|
821
833
|
}
|
|
822
834
|
};
|
|
823
835
|
|
package/dist/index.d.cts
CHANGED
|
@@ -382,8 +382,9 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
382
382
|
constructor(opts?: TOIMCollectionOptions<TEntity, TPk>);
|
|
383
383
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
384
384
|
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
upsertOneByPk(pk: TPk, entity: Partial<TEntity>): void;
|
|
386
|
+
upsertOne(entity: TEntity | Partial<TEntity>): void;
|
|
387
|
+
upsertMany(entities: (TEntity | Partial<TEntity>)[]): void;
|
|
387
388
|
removeOne(entity: TEntity): void;
|
|
388
389
|
removeMany(entities: TEntity[]): void;
|
|
389
390
|
removeOneByPk(pk: TPk): void;
|
|
@@ -392,7 +393,8 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
392
393
|
countAll(): number;
|
|
393
394
|
getAll(): TEntity[];
|
|
394
395
|
getAllPks(): TPk[];
|
|
395
|
-
protected upsertOneWithoutNotifications(entity: TEntity): TPk;
|
|
396
|
+
protected upsertOneWithoutNotifications(entity: TEntity | Partial<TEntity>): TPk;
|
|
397
|
+
protected upsertOneWithoutNotificationsByPk(pk: TPk, entity: Partial<TEntity> | TEntity): void;
|
|
396
398
|
}
|
|
397
399
|
|
|
398
400
|
declare enum EOIMCollectionEventType {
|
package/dist/index.d.ts
CHANGED
|
@@ -382,8 +382,9 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
382
382
|
constructor(opts?: TOIMCollectionOptions<TEntity, TPk>);
|
|
383
383
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
384
384
|
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
upsertOneByPk(pk: TPk, entity: Partial<TEntity>): void;
|
|
386
|
+
upsertOne(entity: TEntity | Partial<TEntity>): void;
|
|
387
|
+
upsertMany(entities: (TEntity | Partial<TEntity>)[]): void;
|
|
387
388
|
removeOne(entity: TEntity): void;
|
|
388
389
|
removeMany(entities: TEntity[]): void;
|
|
389
390
|
removeOneByPk(pk: TPk): void;
|
|
@@ -392,7 +393,8 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
392
393
|
countAll(): number;
|
|
393
394
|
getAll(): TEntity[];
|
|
394
395
|
getAllPks(): TPk[];
|
|
395
|
-
protected upsertOneWithoutNotifications(entity: TEntity): TPk;
|
|
396
|
+
protected upsertOneWithoutNotifications(entity: TEntity | Partial<TEntity>): TPk;
|
|
397
|
+
protected upsertOneWithoutNotificationsByPk(pk: TPk, entity: Partial<TEntity> | TEntity): void;
|
|
396
398
|
}
|
|
397
399
|
|
|
398
400
|
declare enum EOIMCollectionEventType {
|
package/dist/index.js
CHANGED
|
@@ -708,6 +708,10 @@ var OIMCollection = class {
|
|
|
708
708
|
getManyByPks(pks) {
|
|
709
709
|
return this.store.getManyByPks(pks);
|
|
710
710
|
}
|
|
711
|
+
upsertOneByPk(pk, entity) {
|
|
712
|
+
this.upsertOneWithoutNotificationsByPk(pk, entity);
|
|
713
|
+
this.emitter.emit(0 /* UPDATE */, { pks: [pk] });
|
|
714
|
+
}
|
|
711
715
|
upsertOne(entity) {
|
|
712
716
|
const pk = this.upsertOneWithoutNotifications(entity);
|
|
713
717
|
this.emitter.emit(0 /* UPDATE */, { pks: [pk] });
|
|
@@ -751,6 +755,15 @@ var OIMCollection = class {
|
|
|
751
755
|
}
|
|
752
756
|
upsertOneWithoutNotifications(entity) {
|
|
753
757
|
const pk = this.selectPk(entity);
|
|
758
|
+
this.upsertOneWithoutNotificationsByPk(pk, entity);
|
|
759
|
+
return pk;
|
|
760
|
+
}
|
|
761
|
+
upsertOneWithoutNotificationsByPk(pk, entity) {
|
|
762
|
+
if (!pk) {
|
|
763
|
+
throw new Error(
|
|
764
|
+
`[OIMCollection]: PK is required to upsert an entity ${JSON.stringify(entity)}`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
754
767
|
const existingEntity = this.store.getOneByPk(pk);
|
|
755
768
|
if (existingEntity) {
|
|
756
769
|
this.store.setOneByPk(
|
|
@@ -760,7 +773,6 @@ var OIMCollection = class {
|
|
|
760
773
|
} else {
|
|
761
774
|
this.store.setOneByPk(pk, entity);
|
|
762
775
|
}
|
|
763
|
-
return pk;
|
|
764
776
|
}
|
|
765
777
|
};
|
|
766
778
|
|