Open gbabula opened 7 years ago
@melissalabbe Was your suggestion to clone or to share options?
I think shared options would solve the particular issue that we've come across. To summarize, we have found that there is often a need to validate and/or extend the options that are passed into the component. Here's a specific example in standings component to illustrate:
Options are validated and extended in the custom model: https://github.mlbam.net/fed-packages-components/fed-component-baseball-standings/blob/master/src/scripts/model/master.js#L32
Even though the custom viewModel has a reference to the options that were passed in to the component, it won't have the extended options from the model so we pass those back in: https://github.mlbam.net/fed-packages-components/fed-component-baseball-standings/blob/master/src/scripts/viewModel/master.js#L62
Since this extending/validating options is a common need it seems like there should be support for this in the component master. We shouldn't need a custom model to perform this step, and once the options are extended we'd ideally be able to access them in the model and viewModel.
With the new DI model I'm proposing, you can modify the opts in the constructor like so:
class YourComponent extends G5Component {
constructor(opts) {
// Here do anything you need to opts, and build the DI container.
super(opts, implementation);
}
}
// Traditional factory function top level for your component.
export default function (opts) {
return new YourComponent(opts);
}
The super(opts, implementation)
call will still copy the opts unless we specifically remove that, but you make your modifications before that, they will at least propagate to all MVM/Event elements.
g5-component.js v3
Updates and improvements for the next major release.
--
Core
Model
data
eventBuild
src/static/
-->dist/
) (https://github.com/MajorLeagueBaseball/g5-component/pull/16)jshint
dependency in favor ofeslint
(#24)esdoc
dependency, generate documentation reference (#24)ghooks
in favor ofhusky
(#24)tape
dependency in favor ofmocha
(#24)Documentation
core-architecture.md
Suggestions
Browserify
& Aliases (aliases: https://github.com/MajorLeagueBaseball/g5-component/pull/20)component/master
#render
viewModel
,model
, etc... (#20)viewModel
,model
etc... (#20)postcss
andautoprefixer
Other