-
Notifications
You must be signed in to change notification settings - Fork 78
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
Store Middleware #391
Conversation
src/core/middleware/store.ts
Outdated
|
||
const factory = create({ destroy, invalidator }); | ||
|
||
export const createStoreMiddleware = <S = any>(initial?: Function) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/core/middleware/store.ts
Outdated
const factory = create({ destroy, invalidator }); | ||
|
||
export const createStoreMiddleware = <S = any>(initial?: Function) => { | ||
let store = new Store(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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);
65f3a89
to
5b5ab6b
Compare
return storeMiddleware; | ||
}; | ||
|
||
export default createStoreMiddleware; |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
src/core/middleware/store.ts
Outdated
return (store as any).path(path, ...segments); | ||
}; | ||
return { | ||
get<U = any>(path: Path<S, U>, subscribe = true): U { |
There was a problem hiding this comment.
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
5b5ab6b
to
f78a33f
Compare
f78a33f
to
737437c
Compare
Type: feature
The following has been addressed in the PR:
prettier
as per the readme code style guidelinesDescription:
Dojo stores middleware
Resolves #397