Skip to content
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

update ember-data related syntax #1116

Merged
merged 3 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions addon/adapters/-addon-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import Adapter from '@ember-data/adapter';
import config from 'ember-get-config';
import fetch from 'fetch';

export default Adapter.extend({
defaultSerializer: '-addon-docs',
namespace: `${config.rootURL.replace(/\/$/, '')}/docs`,
export default class AddonDocsAdapter extends Adapter {
defaultSerializer = '-addon-docs';
namespace = `${config.rootURL.replace(/\/$/, '')}/docs`;

shouldBackgroundReloadAll() {
return false;
},
}

shouldBackgroundReloadRecord() {
return false;
},
}

findRecord(store, modelClass, id, snapshot) {
if (modelClass.modelName === 'project') {
Expand All @@ -22,5 +22,5 @@ export default Adapter.extend({
} else {
return store.peekRecord(modelClass.modelName, id);
}
},
});
}
}
3 changes: 1 addition & 2 deletions addon/adapters/class.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import BaseAdapter from './-addon-docs';
SergeAstapov marked this conversation as resolved.
Show resolved Hide resolved
export default BaseAdapter.extend();
export { default } from './-addon-docs';
3 changes: 1 addition & 2 deletions addon/adapters/component.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import BaseAdapter from './-addon-docs';
export default BaseAdapter.extend();
export { default } from './-addon-docs';
3 changes: 1 addition & 2 deletions addon/adapters/module.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import BaseAdapter from './-addon-docs';
export default BaseAdapter.extend();
export { default } from './-addon-docs';
3 changes: 1 addition & 2 deletions addon/adapters/project.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import BaseAdapter from './-addon-docs';
export default BaseAdapter.extend();
export { default } from './-addon-docs';
198 changes: 112 additions & 86 deletions addon/models/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,134 @@ import Model, { attr, belongsTo } from '@ember-data/model';
import { filterBy, or, union } from '@ember/object/computed';
import { memberUnion, hasMemberType } from '../utils/computed';

export default Model.extend({
parentClass: belongsTo('class', { async: false, inverse: null }),

isClass: true,

name: attr(),
file: attr(),
exportType: attr(),
description: attr(),
lineNumber: attr(),
access: attr(),

accessors: attr(),
methods: attr(),
fields: attr(),
tags: attr(),

publicAccessors: filterBy('accessors', 'access', 'public'),
publicMethods: filterBy('methods', 'access', 'public'),
publicFields: filterBy('fields', 'access', 'public'),

privateAccessors: filterBy('accessors', 'access', 'private'),
privateMethods: filterBy('methods', 'access', 'private'),
privateFields: filterBy('fields', 'access', 'private'),

protectedAccessors: filterBy('accessors', 'access', 'protected'),
protectedMethods: filterBy('methods', 'access', 'protected'),
protectedFields: filterBy('fields', 'access', 'protected'),

allPublicAccessors: memberUnion(
'parentClass.allPublicAccessors',
'publicAccessors'
),
allPublicMethods: memberUnion(
'parentClass.allPublicMethods',
'publicMethods'
),
allPublicFields: memberUnion('parentClass.allPublicFields', 'publicFields'),

allPrivateAccessors: memberUnion(
'parentClass.allPrivateAccessors',
'privateAccessors'
),
allPrivateMethods: memberUnion(
'parentClass.allPrivateMethods',
'privateMethods'
),
allPrivateFields: memberUnion(
'parentClass.allPrivateFields',
'privateFields'
),

allProtectedAccessors: memberUnion(
'parentClass.allProtectedAccessors',
'protectedAccessors'
),
allProtectedMethods: memberUnion(
'parentClass.allProtectedMethods',
'protectedMethods'
),
allProtectedFields: memberUnion(
'parentClass.allProtectedFields',
'protectedFields'
),

allAccessors: union(
'allPublicAccessors',
'allPrivateAccessors',
'allProtectedAccessors'
),
allMethods: union(
'allPublicMethods',
'allPrivateMethods',
'allProtectedMethods'
),
allFields: union('allPublicFields', 'allPrivateFields', 'allProtectedFields'),

hasInherited: or(
export default class Class extends Model {
@belongsTo('class', { async: false, inverse: null })
parentClass;

isClass = true;

@attr
name;

@attr
file;

@attr
exportType;

@attr
description;

@attr
lineNumber;

@attr
access;

@attr
accessors;

@attr
methods;

@attr
fields;

@attr
tags;

@filterBy('accessors', 'access', 'public')
publicAccessors;

@filterBy('methods', 'access', 'public')
publicMethods;

@filterBy('fields', 'access', 'public')
publicFields;

@filterBy('accessors', 'access', 'private')
privateAccessors;

@filterBy('methods', 'access', 'private')
privateMethods;

@filterBy('fields', 'access', 'private')
privateFields;

@filterBy('accessors', 'access', 'protected')
protectedAccessors;

@filterBy('methods', 'access', 'protected')
protectedMethods;

@filterBy('fields', 'access', 'protected')
protectedFields;

@memberUnion('parentClass.allPublicAccessors', 'publicAccessors')
allPublicAccessors;

@memberUnion('parentClass.allPublicMethods', 'publicMethods')
allPublicMethods;

@memberUnion('parentClass.allPublicFields', 'publicFields')
allPublicFields;

@memberUnion('parentClass.allPrivateAccessors', 'privateAccessors')
allPrivateAccessors;

@memberUnion('parentClass.allPrivateMethods', 'privateMethods')
allPrivateMethods;

@memberUnion('parentClass.allPrivateFields', 'privateFields')
allPrivateFields;

@memberUnion('parentClass.allProtectedAccessors', 'protectedAccessors')
allProtectedAccessors;

@memberUnion('parentClass.allProtectedMethods', 'protectedMethods')
allProtectedMethods;

@memberUnion('parentClass.allProtectedFields', 'protectedFields')
allProtectedFields;

@union('allPublicAccessors', 'allPrivateAccessors', 'allProtectedAccessors')
allAccessors;

@union('allPublicMethods', 'allPrivateMethods', 'allProtectedMethods')
allMethods;

@union('allPublicFields', 'allPrivateFields', 'allProtectedFields')
allFields;

@or(
'parentClass.allAccessors.length',
'parentClass.allMethods.length',
'parentClass.allFields.length'
),
)
hasInherited;

hasPrivate: or(
@or(
'allPrivateAccessors.length',
'allPrivateMethods.length',
'allPrivateFields.length'
),
)
hasPrivate;

hasProtected: or(
@or(
'allProtectedAccessors.length',
'allProtectedMethods.length',
'allProtectedFields.length'
),
)
hasProtected;

hasDeprecated: hasMemberType(
@hasMemberType(
'allFields',
'allAccessors',
'allMethods',

function (member) {
return member.tags && member.tags.find((t) => t.name === 'deprecated');
}
),
});
)
hasDeprecated;
}
82 changes: 44 additions & 38 deletions addon/models/component.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,72 @@
import { attr } from '@ember-data/model';
import { filterBy, or } from '@ember/object/computed';
import { dasherize } from '@ember/string';
import { computed } from '@ember/object';

import Class from './class';
import { memberUnion, hasMemberType } from '../utils/computed';

export default Class.extend({
isComponent: true,
export default class Component extends Class {
isComponent = true;

yields: attr(),
arguments: attr(),
@attr
yields;

overloadedYields: or('yields', 'inheritedYields'),
@attr
arguments;

publicArguments: filterBy('arguments', 'access', 'public'),
privateArguments: filterBy('arguments', 'access', 'private'),
protectedArguments: filterBy('arguments', 'access', 'protected'),
@or('yields', 'inheritedYields')
overloadedYields;

allPublicArguments: memberUnion(
'parentClass.allPublicArguments',
'publicArguments'
),
allPrivateArguments: memberUnion(
'parentClass.allPrivateArguments',
'privateArguments'
),
allProtectedArguments: memberUnion(
'parentClass.allProtectedArguments',
'protectedArguments'
),
@filterBy('arguments', 'access', 'public')
publicArguments;

allArguments: memberUnion('parentClass.allArguments', 'arguments'),
@filterBy('arguments', 'access', 'private')
privateArguments;

hasInherited: or(
@filterBy('arguments', 'access', 'protected')
protectedArguments;

@memberUnion('parentClass.allPublicArguments', 'publicArguments')
allPublicArguments;

@memberUnion('parentClass.allPrivateArguments', 'privateArguments')
allPrivateArguments;

@memberUnion('parentClass.allProtectedArguments', 'protectedArguments')
allProtectedArguments;

@memberUnion('parentClass.allArguments', 'arguments')
allArguments;

@or(
'parentClass.overloadedYields.length',
'parentClass.allArguments.length',
'parentClass.allAccessors.length',
'parentClass.allMethods.length',
'parentClass.allFields.length'
),
)
hasInherited;

hasInternal: or(
'allAccessors.length',
'allMethods.length',
'allFields.length'
),
@or('allAccessors.length', 'allMethods.length', 'allFields.length')
hasInternal;

hasPrivate: or(
@or(
'allPrivateAccessors.length',
'allPrivateArguments.length',
'allPrivateMethods.length',
'allPrivateFields.length'
),
)
hasPrivate;

hasProtected: or(
@or(
'allProtectedAccessors.length',
'allProtectedArguments.length',
'allProtectedMethods.length',
'allProtectedFields.length'
),
)
hasProtected;

hasDeprecated: hasMemberType(
@hasMemberType(
'allAccessors',
'allArguments',
'allMethods',
Expand All @@ -70,7 +75,8 @@ export default Class.extend({
function (member) {
return member.tags && member.tags.find((t) => t.name === 'deprecated');
}
),
)
hasDeprecated;

/*
This gives us a way to link to a model, since we don't always link by the actual ID:
Expand All @@ -79,7 +85,7 @@ export default Class.extend({

Possible refactoring is to always link by actual ID, and implement redirects.
*/
routingId: computed('name', function () {
get routingId() {
return `components/${dasherize(this.name)}`;
}),
});
}
}
Loading