Skip to content

v7.0.2

Choose a tag to compare

@KeithWoods KeithWoods released this 22 Nov 11:14
· 41 commits to master since this release

See PR #310 for details.

ESP 7

The main changes in are to esp-js-polimer and esp-js-react, however, there were some minor changes to esp-js and several outdated depenencies were updated.

esp-js: Router's publish API

You can now pass an object conforming to shape ModelAddress ({modelId: string, entityKey: string}) to publish:

  • publishEvent(modelId: string, eventType: string, event: any) : void;
  • public publishEvent(modelAddress: ModelAddress, eventType: string, event: any) : void;

If you set the entityKey esp-js will include this on the events Envelope and the EventContext being dispatched.
This allows for other code to perform finer deliver of the event in question (for example, you can refer to the entityKey in various filters/predicates).

esp-js-polimer: Dynamically expand and contract esp-js-polimer based models

A new API, modelUpdater has been added to polimers model builder.
The API also now includes a predicate which can be used to filter which events get delivered to the handlers / transforms being registered.
For example:

router
    .modelUpdater<DynamicProductTileModel>(this._modelId)
    .withStateHandlers(
        'products',
        // we add a registration filter which limits these handler instances to this specific entityKey
        (e: EventEnvelope<unknown, DynamicProductTileModel>) => e.context.entityKey === entityKey,
        ...stateHandlers
    )
    .withEventTransforms(
        // we add a registration filter which limits these handler instances to this specific entityKey
        (e: EventEnvelope<unknown, DynamicProductTileModel>) => e.context.entityKey === entityKey,
        ...eventTransforms
    )
    .updateRegistrationsWithRouter();

## esp-js-polimer: API Renames

The following model builder registration functions where renamed, the old ones exist for backwards compatability:

  • withStateHandlerObject -> withStateHandlers
  • withEventStreamsOn -> withEventTransforms

OutputEvent has it's addressing property renamed from modelId:string to address: ModelAddress.
modelId is still supported for backwards compatability:

esp-js-polimer: Support for Map<string, object> states

You can now include a JS Map as a state item:

export interface MyModel {
    products: Map<string, MyEntity>;
}

If you publish events to state handlers registered against this map, and include the entityKey, polimer will pull the item from the map and deliver that to your handler:

// handler registration:
let polimerModel = this._router
    .modelBuilder<DynamicProductTileModel, DynamicProductPersistedState>()
    // ... other config
    .withStateHandlers('products', new ProductCurrencyPairStateHandler())

// view: 
router.publish({modelId: 'theModelId', entityKey: 'keyFromMap' }, 'ccyPair_changed', theEvent);

// handler: it recieves the item from the Map
export class ProductCurrencyPairStateHandler {
    @observeEvent(DynamicProductEvents.Products.CommonProductEvents.ccyPair_changed)
    _ccyPair_changed(draft:Product, event: DynamicProductEvents.Products.CommonProductEvents.CcyPairChangedEvent) {
        draft.ccyPairField.ccyPair = event.newCcyPair;
    }
}

You can combine the above with registration predicates to have only selected handlers called for given entityKeys.

You can omit the entityKey and get the full map as your state, just like any other entity on the state bag.

esp-js-react

There are new context types added, these are exposed via various useXXX 'hook' type functions:

  • useGetModelId(): () => string;
  • usePublishEvent(): (modelIdOrModelAddress: string | ModelAddress, eventType: string, event: any) => void;
  • usePublishModelEvent(): (eventType: string, event: any) => void;
  • usePublishModelEventWithEntityKey(): (entityKey: string, eventType: string, event: any) => void;

Note: while some of these already existed, they were not exposed via useXXX functions.

Major Dependencies Updated

  • Jest
  • Webpack
  • TypeScript

React will be updated in a followup, this is largely as esp-js-react needs to move from Enzime to React Testing Library.

esp-js-ui-module-based-app

This has been updated to include a 'Dynamic Product' view which shows how all of the above features work together.