Changing the Firefly Semantics Slice EStore Default Configuration | Task

Ole Ersoy
Feb - 11  -  2 min

Scenario

The default configuration for Firefly Semantics Slice entities expects entities to have a id and gid property.

We are creating a EStore<Todo> for Todo entities and we want the global id property to be guid instead of gid.

Approach

The StoreConfig interface looks like this:

interface StoreConfig {    
   idKey: string;
   guidKey: string;
};

Create a new configuration object:

const config: StoreConfig = { guidKey: 'guid' }

Pass it to the constructor when initializing the store:

let store: EStore<Todo> = new EStore<Todo>(todos, config);

To see what the current global id property name is check store.GUID_KEY.

To see what the current global id property name is check store.ID_KEY.

The below demo logs the result of this operation:

console.log(`The Global ID Key is: ${store.GUID_KEY}`);
console.log(`The ID Key is: ${store.ID_KEY}`);

Demo

We can see by logging store contents that each entity now has a guid property initialized with a global ID:

[{"id":"1","complete":false,"title":"You complete me!","guid":"J2yGsD9Z5tdXsux1kLaet"},{"id":"2","complete":true,"title":"You completed me!","guid":"wIBAvxyquUo9Tqj-Kzilz"}]