Skip to content

Commit

Permalink
refactor: octane dummy app files (#474)
Browse files Browse the repository at this point in the history
refactor: native class for some dummy app files
  • Loading branch information
Techn1x authored Dec 6, 2022
1 parent 1d6cd99 commit 9be78a4
Show file tree
Hide file tree
Showing 66 changed files with 312 additions and 303 deletions.
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,26 @@ In the following examples, assume the models look like this:

```javascript
// standard models
User = DS.Model.extend({
name: DS.attr('string'),
style: DS.attr('string'),
projects: DS.hasMany('project'),
hats: DS.hasMany('hat', {polymorphic: true})
});
class User extends Model {
@attr('string') name
@attr('string') style
@hasMany('project') projects
@hasMany('hat', {polymorphic: true}) hats
}

Project = DS.Model.extend({
title: DS.attr('string'),
user: DS.belongsTo('user')
});
class Project extends Model {
@attr('string') title
@belongsTo('user') user
}

// polymorphic models
Hat = DS.Model.extend({
type: DS.attr('string'),
user: DS.belongsTo('user')
});
class Hat extends Model {
@attr('string') type
@belongsTo('user') user
}

BigHat = Hat.extend();
SmallHat = Hat.extend();
class BigHat extends Hat {};
class SmallHat extends Hat {};
```

### Defining Factories
Expand Down Expand Up @@ -561,10 +561,10 @@ Let's say you have a model and a factory like this:
import Model from 'ember-data/model';
import attr from 'ember-data/attr';

export default Model.extend({
dogNumber: attr('string'),
sound: attr('string')
});
export default class Dog extends Model{
@attr('string') dogNumber
@attr('string') sound
}

// tests/factories/dog.js
import FactoryGuy from 'ember-data-factory-guy';
Expand Down Expand Up @@ -1071,23 +1071,23 @@ For example, say we have the following `Employee` model which makes use of the `
```javascript
// Employee model
export default Model.extend({
name: fragment('name'),
phoneNumbers: fragmentArray('phone-number')
})
export default class Employee extends Model {
@fragment('name') name
@fragmentArray('phone-number') phoneNumbers
}

// Name fragment
export default Fragment.extend({
titles: array('string'),
firstName: attr('string'),
lastName: attr('string')
});
export default class Name extends Fragment {
@array('string') titles
@attr('string') firstName
@attr('string') lastName
}

// Phone Number fragment
export default Fragment.extend({
number: attr('string')
type: attr('string')
});
export default class PhoneNumber extends Fragment {
@attr('string') number
@attr('string') type
}
```
A factory for this model and its fragments would look like so:
Expand Down Expand Up @@ -2086,18 +2086,18 @@ describe('Admin View', function() {
```javascript
// app/serializers/person.js
export default DS.RESTSerializer.extend({
export default class PersonSerializer extends RESTSerializer {
// let's say you're modifying all names to be Japanese honorific style
serialize: function(snapshot, options) {
serialize(snapshot, options) {
var json = this._super(snapshot, options);
let honorificName = [snapshot.record.get('name'), 'san'].join('-');
json.name = honorificName;
return json;
}
});
}
// somewhere in your tests
let person = make('person', {name: "Daniel"});
Expand Down
8 changes: 4 additions & 4 deletions addon/factory-guy.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class FactoryGuy {
/**
```javascript
Person = DS.Model.extend({
type: DS.attr('string'),
name: DS.attr('string')
})
class Person extends Model {
@attr('string') type
@attr('string') name
}
FactoryGuy.define('person', {
sequences: {
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import AdapterFetch from 'ember-fetch/mixins/adapter-fetch';
import JSONAPIAdapter from '@ember-data/adapter/json-api';

export default JSONAPIAdapter.extend(AdapterFetch);
export default class extends JSONAPIAdapter.extend(AdapterFetch) {}
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/profiles.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import Controller from '@ember/controller';
export default Controller.extend();
export default class extends Controller {}
11 changes: 11 additions & 0 deletions tests/dummy/app/controllers/search/results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Controller from '@ember/controller';

export default class extends Controller {
get previousPage() {
return this.model.meta?.previous;
}

get nextPage() {
return this.model.meta?.next;
}
}
14 changes: 7 additions & 7 deletions tests/dummy/app/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default Controller.extend({
actions: {
deleteUser(user) {
return user.destroyRecord();
},
},
});
export default class extends Controller {
@action
deleteUser(user) {
return user.destroyRecord();
}
}
6 changes: 3 additions & 3 deletions tests/dummy/app/models/big-group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Group from './group';
import { attr } from '@ember-data/model';

export default Group.extend({
type: attr('string', { defaultValue: 'BigGroup' }),
});
export default class extends Group {
@attr('string', { defaultValue: 'BigGroup' }) type;
}
6 changes: 3 additions & 3 deletions tests/dummy/app/models/big-hat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Hat from './hat';
import { hasMany } from '@ember-data/model';

export default Hat.extend({
materials: hasMany('soft-material', { async: false }),
});
export default class extends Hat {
@hasMany('soft-material', { async: false }) materials;
}
6 changes: 3 additions & 3 deletions tests/dummy/app/models/billing-address.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { attr } from '@ember-data/model';
import Address from 'dummy/models/nested-fragment/address';

export default Address.extend({
billingAddressProperty: attr('number'),
});
export default class extends Address {
@attr('number') billingAddressProperty;
}
10 changes: 5 additions & 5 deletions tests/dummy/app/models/cat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Model, { attr } from '@ember-data/model';

export default Model.extend({
type: attr('string'),
name: attr('string'),
friend: attr('string'),
});
export default class extends Model {
@attr('string') type;
@attr('string') name;
@attr('string') friend;
}
12 changes: 6 additions & 6 deletions tests/dummy/app/models/comic-book.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Model, { attr, hasMany, belongsTo } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
company: belongsTo('company'),
characters: hasMany('person', { polymorphic: true }),
includedVillains: hasMany('villain'),
});
export default class extends Model {
@attr('string') name;
@belongsTo('company') company;
@hasMany('person', { polymorphic: true }) characters;
@hasMany('villain') includedVillains;
}
14 changes: 7 additions & 7 deletions tests/dummy/app/models/company.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Model, { attr, hasMany, belongsTo } from '@ember-data/model';

export default Model.extend({
type: attr('string', { defaultValue: 'Company' }),
name: attr('string'),
profile: belongsTo('profile', { async: false }),
users: hasMany('user', { async: true, inverse: 'company' }),
projects: hasMany('project', { async: true }),
});
export default class extends Model {
@attr('string', { defaultValue: 'Company' }) type;
@attr('string') name;
@belongsTo('profile', { async: false }) profile;
@hasMany('user', { async: true, inverse: 'company' }) users;
@hasMany('project', { async: true }) projects;
}
2 changes: 1 addition & 1 deletion tests/dummy/app/models/cool-stoner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Stoner from './stoner';

export default Stoner.extend();
export default class extends Stoner {}
10 changes: 5 additions & 5 deletions tests/dummy/app/models/department-employment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { attr } from '@ember-data/model';
import Fragment from 'ember-data-model-fragments/fragment';
import { fragment } from 'ember-data-model-fragments/attributes';

export default Fragment.extend({
startDate: attr('date'),
endDate: attr('date'),
department: fragment('department'),
});
export default class extends Fragment {
@attr('date') startDate;
@attr('date') endDate;
@fragment('department') department;
}
11 changes: 6 additions & 5 deletions tests/dummy/app/models/department.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { attr } from '@ember-data/model';
import Fragment from 'ember-data-model-fragments/fragment';
import { fragmentArray } from 'ember-data-model-fragments/attributes';

export default Fragment.extend({
name: attr('string'),
addresses: fragmentArray('nested-fragment/address', {
export default class extends Fragment {
@attr('string') name;
@fragmentArray('nested-fragment/address', {
polymorphic: true,
typeKey: '$type',
}),
});
})
addresses;
}
12 changes: 6 additions & 6 deletions tests/dummy/app/models/dog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Model, { attr, belongsTo } from '@ember-data/model';

export default Model.extend({
owner: belongsTo('person'),
dogNumber: attr('string'),
sound: attr('string'),
tag: attr(), // hash
});
export default class extends Model {
@belongsTo('person') owner;
@attr('string') dogNumber;
@attr('string') sound;
@attr() tag; // hash
}
18 changes: 9 additions & 9 deletions tests/dummy/app/models/employee.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
fragmentArray,
} from 'ember-data-model-fragments/attributes';

export default Model.extend({
designation: fragment('name'),
name: fragment('name'),
titles: array('string'),
gender: attr('string'),
birthDate: attr('date'),
position: attr(),
departmentEmployments: fragmentArray('department-employment'),
});
export default class extends Model {
@fragment('name') designation;
@fragment('name') name;
@array('string') titles;
@attr('string') gender;
@attr('date') birthDate;
@attr() position;
@fragmentArray('department-employment') departmentEmployments;
}
8 changes: 4 additions & 4 deletions tests/dummy/app/models/entry-type.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Model, { attr, hasMany } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
entries: hasMany('entry'),
});
export default class extends Model {
@attr('string') name;
@hasMany('entry') entries;
}
8 changes: 4 additions & 4 deletions tests/dummy/app/models/entry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Model, { attr, belongsTo } from '@ember-data/model';

export default Model.extend({
name: attr('string'),
entryType: belongsTo('entry-type'),
});
export default class extends Model {
@attr('string') name;
@belongsTo('entry-type') entryType;
}
9 changes: 5 additions & 4 deletions tests/dummy/app/models/fluffy-material.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Material from './material';
import { belongsTo } from '@ember-data/model';

export default Material.extend({
hat: belongsTo('hat', {
export default class extends Material {
@belongsTo('hat', {
async: false,
inverse: 'fluffyMaterials',
polymorphic: true,
}),
});
})
hat;
}
20 changes: 11 additions & 9 deletions tests/dummy/app/models/group.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import Model, { attr, hasMany, belongsTo } from '@ember-data/model';

export default Model.extend({
type: attr('string', { defaultValue: 'Group' }),
name: attr('string'),
profiles: hasMany('profile', { async: false, inverse: 'group' }),
versions: hasMany('group', {
export default class extends Model {
@attr('string', { defaultValue: 'Group' }) type;
@attr('string') name;
@hasMany('profile', { async: false, inverse: 'group' }) profiles;
@hasMany('group', {
async: false,
polymorphic: true,
inverse: 'group',
}),
group: belongsTo('group', {
})
versions;
@belongsTo('group', {
async: false,
polymorphic: true,
inverse: 'versions',
}),
});
})
group;
}
Loading

0 comments on commit 9be78a4

Please sign in to comment.