-
Notifications
You must be signed in to change notification settings - Fork 2
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
AbstractDetail should use Resolver data as is #37
Comments
Not exactly. While answering you, I found out there are some incoherences in resolving and defaulting data. Probably the result of many iterations. There are two differences to take in consideration : Default values more consistentlyWe should change if (id) {
- observable = this.getOne(id);
+ observable = merge(this.getConsolidatedForClient(), this.getOne(id)}; ngOnInit would be simplified : - this.data = merge({model: this.service.getConsolidatedForClient()}, data[this.key]);
+ this.data = merge({model: data[this.key]); This would have another impact : apply default values returned by the server on all resolved items. Actually, only the main one is defaulted in controller side. Before (actually consolidated is unconsistant) : {main: {model: consolidatedFetched } }
{other: {model: fetchedOther } } After (all resolved models are consolidated) : {main: {model: consolidatedFetched } }
{other: {model: consolidatedFetchedOther } } Important : that means Resolvers must always be provided, there is no fallback. An error could be sent if nothing has been provided in data[this.key]... ? Template accessWhen we resolve something, we declare it in routing this way (we can have multiple resolvers) : {
resolve : {
action: ActionResolver,
other: OtherResolver
}
} In controller, {action: {model: fetchedAction, statuses : [...], priorities : [...]} }
{other: {model: fetchedOther } } In AbstractDetail.ngOnInit it targets // action item is consolidated and "action" key becomes "model"
{model: consolidatedFetchedAction, statuses : [...], priorities : [...]}
{other: {model: fetchedOther } } At this final stage, templates access If we replace ngOnInit as you suggest, we would have : {action: {model: consolidatedFetchedAction, statuses : [...], priorities : [...]} }
{other: {model: fetchedOther } } And all templates should be updated to access |
We can easily consolidate with first step : moving getConsolidatedForClient in resolve() and clear it from AbstractDetail.ngOnInit. And if you are motivated to update all templates, you can process the second step : change AbstractDetail.ngOnInit as you suggest. |
If we change something that impacts the template, we must adapt PanelService to expose the same object structure of resolved items to the template. Same components are used in Panel routing and Angular routing. |
yes... but I am not sure in what case we need to add default values to something that already is persisted in DB, so assumed to be valid.
yes I didn't think of the impact on templates though... I also didn't realize that our current situation feels a little bit inconsistent between // action item is consolidated and "action" key becomes "model"
{model: consolidatedFetchedAction, statuses : [...], priorities : [...]}
{other: {model: fetchedOther } } But actually I didn't find any cases of grep '--include=*.html' -hPor 'data\.\w+\.model' client/app/ | sort -u I suggest we create a PR and review it before merging. |
In
NaturalAbstractDetail.ngOnInit
I think we should simplify like so:If my understanding is correct we try force default values on whatever is coming from the route. But the route is already populated with default value via
NaturalAbstractModelService.resolve
who calledgetConsolidatedForClient
earlier. So our current code seems to be entirely redundant as long as we properly use revolvers.So we should double-check that resolvers are used correctly in all our projects and simplify this code.
The text was updated successfully, but these errors were encountered: