I don't think having plugins that call methods to pass options will work with AoT.
@amcdnl I added a PR for a demo app. we could potentially use that to test a lot of these senarios
Let me know when ur ready to merge it.
@amcdnl now that the scaffolding is place we can add a test for this
Just as expected ->
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'LocalStoragePlugin' was called.
I can help trouble shoot this week
example of where plugins could evolve
https://stackblitz.com/edit/test-plugin
Thats what i was thinking too. I was tinkering with this last night. The plugins array actually gets tranposed into providers so we can just pass the options there.
Idea ->
Ngxs.forRoot([MyStore], {
plugins: [MyPlugin],
pluginOptions: [{}]
})
I think that is at least a staring point for the API
@amcdnl actually. the more I think about it, I don't think that will work. I think we will have to do this the way http interceptors handles it and I think individual plugins should be responsible for defining how options are passed to them.
I Think all Ngxs should be responsible for is defining what a plugin looks like and instructions on how to provide them.
A plugin author could then expose the configuration to make it easy for the app dev.
import { STORE_PLUGINS } from 'ngxs';
import { MyPlugin } from './my.plugin';
export MY_PLUGIN = {
provide: STORE_PLUGINS,
useClass: MyPlugin,
multi: true
}
Article about interceptors
https://medium.com/@ryanchenkie_40935/angular-authentication-using-the-http-client-and-http-interceptors-2f9d1540eb8
Ok but how would I configure an out of the box plugin? Sounds like this solution you’d have to extend the plugin which is kinda nasty
Not at all. The plugin author would have to provide and injection token for config options
Can you show an example of passing plugins to a out-of-the-box plugin?
Yes
@amcdnl check back at the stack blitz I made and tell me what you think.
https://stackblitz.com/edit/test-plugin?file=app%2Fapp.module.ts
uses a static function to return the providers which then allows you to pass in options (also works with AOT). it isn't configured by passing it into a stores forRoot method but it doesn't feed like a bad pattern
They have a plugin system, might be worth checking out - https://github.com/SebastianM/tinystate
I think k they actually do what I was suggesting
On Thu, Mar 8, 2018, 6:27 PM Austin notifications@github.com wrote:
They have a plugin system, might be worth checking out -
https://github.com/SebastianM/tinystate—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/amcdnl/ngxs/issues/16#issuecomment-371660512, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AGQnJfWUcpiB6tXVuYrPE54X1d2ddnmjks5tcb5qgaJpZM4SbW35
.
@amcdnl yeah they are defining a plugin as a module and using DI to set configs. which I believe you had suggested
@amcdnl update stack blitz to show what I think