Skip to content

Priority for already loaded record #329

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/routes/project-version/classes/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default Route.extend(ScrollTracker, {
metaStore: service(),

titleToken: function(model) {
return model.get('name');
return get(model, 'name');
},

model(params, transition) {
Expand All @@ -20,14 +20,19 @@ export default Route.extend(ScrollTracker, {

getModel(typeName, params, transition) {
const projectID = transition.params['project-version'].project;
let compactVersion = transition.params['project-version'].project_version;
const compactVersion = transition.params['project-version'].project_version;
const projectVersion = this.get('metaStore').getFullVersion(projectID, compactVersion);

const klass = params[typeName];
return this.find(typeName, `${projectID}-${projectVersion}-${klass}`);
const key = `${projectID}-${projectVersion}-${klass}`;
const localModel = this.store.peekRecord(typeName, key);
return localModel ? resolve(localModel) : this.find(typeName, key);
},

find(typeName, param) {
const loadedRecord = this.store.peekRecord(typeName, param);
if (loadedRecord) {
return resolve(loadedRecord);
}
return this.store.find(typeName, param).catch(() => {
return this.store.find('namespace', param).catch(() => {
return resolve({ isError: true });
Expand All @@ -43,7 +48,7 @@ export default Route.extend(ScrollTracker, {

afterModel(klass) {
if (!klass.isError) {
set(this, 'headData.description', klass.get('ogDescription'));
set(this, 'headData.description', get(klass, 'ogDescription'));
const relationships = get(klass.constructor, 'relationshipNames');
const promises = Object.keys(relationships).reduce((memo, relationshipType) => {
const relationshipPromises = relationships[relationshipType].map(name => klass.get(name));
Expand All @@ -55,7 +60,7 @@ export default Route.extend(ScrollTracker, {

serialize(model) {
return {
class: model.get('name')
class: get(model, 'name')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Turbo87 class route alteady has import { set, get } from '@ember/object';, why not to use them?

Copy link
Contributor

Choose a reason for hiding this comment

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

because they are much harder to read IMHO and only make sense if model was a POJO and not an Ember.Object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rolled-back

};
}

Expand Down
2 changes: 1 addition & 1 deletion app/services/filter-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Service from '@ember/service';

export default Service.extend({
showInherited: false,
showInherited: true,
Copy link
Member

Choose a reason for hiding this comment

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

we wouldn't want to change this behaviour for now

Copy link
Contributor Author

@lifeart lifeart Aug 29, 2017

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

showProtected: false,
showPrivate: false,
showDeprecated: false,
Expand Down
3 changes: 3 additions & 0 deletions app/templates/project-version/classes/class-loading.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<article class="chapter">
{{loading-spinner}}
</article>
3 changes: 3 additions & 0 deletions app/templates/project-version/modules/module-loading.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<article class="chapter">
{{loading-spinner}}
</article>