Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store Middleware #391

Merged
merged 3 commits into from
Jun 14, 2019
Merged

Store Middleware #391

merged 3 commits into from
Jun 14, 2019

Conversation

agubler
Copy link
Member

@agubler agubler commented Jun 7, 2019

Type: feature

The following has been addressed in the PR:

Description:

Dojo stores middleware

Resolves #397


const factory = create({ destroy, invalidator });

export const createStoreMiddleware = <S = any>(initial?: Function) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supports running an optional initial set of processes to bootstrap the store data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The factory is used to type the store middleware for the application state

const factory = create({ destroy, invalidator });

export const createStoreMiddleware = <S = any>(initial?: Function) => {
let store = new Store();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The store is factory'd for the middleware, does not use the store from the injector - We might want to support the injector from the store for backwards compatibility (so that users can progressively adopt functional widgets and middleware)

return (store as any).path(path, ...segments);
};
return {
get<U = any>(path: Path<S, U>): U {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically registers paths to invalidate on for a widget

at<U = any>(path: Path<S, U[]>, index: number) {
return store.at(path, index);
},
executor<T extends Process<any, any>>(process: T): ReturnType<T> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function that returns an executor from a process, const exec = executor(process) is equivalent to const exec = process(store);

@agubler agubler changed the title [WIP] Store Middleware Store Middleware Jun 13, 2019
return storeMiddleware;
};

export default createStoreMiddleware;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exports a factory that creates the middleware, this is so that it can be typed with the store state interface, also factories a Store that is shared across all instances of the middleware.


const factory = create({ destroy, invalidator, injector });

export const createStoreMiddleware = <S = any>(initial?: (store: Store<S>) => void) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepts an optional initial (perhaps should be called init or initialize) function that receives the factorie'd store and can initialize state etc.

handle();
}
});
if (!initialized) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a one time check for a store in the application registry, if it exists the middleware will use that instead

return (store as any).path(path, ...segments);
};
return {
get<U = any>(path: Path<S, U>, subscribe = true): U {
Copy link
Member Author

@agubler agubler Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equivalent to the store's get API except it will automatically subscribe the widget to data updates for all the paths used. This can be manually disabled on a call by call basis by passing false as the second argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store Middleware
2 participants