Skip to content

Commit

Permalink
feat(com-pwa): central context.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Feb 11, 2023
1 parent 8aa6e8f commit 37e3c93
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
25 changes: 25 additions & 0 deletions uniquely/com-pwa/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
contextConsumer,
contextProvider,
requestableContextConsumer,
requestableContextProvider,
commandTrigger,
} from '@alwatr/signal';

import type {AlwatrDocumentStorage, User} from '@alwatr/type';
import type {Product, Order} from '@alwatr/type/customer-order-management.js';

export const productStorageContextConsumer =
contextConsumer.bind<AlwatrDocumentStorage<Product>>('product-storage-context');

export const orderStorageContextProvider =
requestableContextProvider.bind<AlwatrDocumentStorage<Order>, null>('order-storage-context');

export const orderStorageContextConsumer =
requestableContextConsumer.bind<AlwatrDocumentStorage<Order>, null>(orderStorageContextProvider.id);


export const userContextProvider = contextProvider.bind<User>('user-context');
export const userContextConsumer = contextConsumer.bind<User>(userContextProvider.id);

export const submitOrderCommandTrigger = commandTrigger.bind<Partial<Order>, Order>('submit-order-command');
2 changes: 1 addition & 1 deletion uniquely/com-pwa/src/director/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import './content-provider.js';
import './product-storage-context-provider.js';
import './/user-context-provider.js';
import './order-storage-context-provider.js';
import './put-order-provider.js';
import './submit-order-handler.js';
5 changes: 2 additions & 3 deletions uniquely/com-pwa/src/director/user-context-provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {contextProvider} from '@alwatr/signal';
import {getLocalStorageItem} from '@alwatr/util';

import type {User} from '@alwatr/type';
import {userContextProvider} from '../context.js';

// demo
contextProvider.setValue<User>('user-context', getLocalStorageItem('user-context', {
userContextProvider.setValue(getLocalStorageItem('user-context', {
id: 'demo-123',
fullName: 'Demo User',
}));

0 comments on commit 37e3c93

Please sign in to comment.