-
Notifications
You must be signed in to change notification settings - Fork 47
/
fruit.js
30 lines (27 loc) · 890 Bytes
/
fruit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// BEGIN-SNIPPET fruit-model
import DS from 'ember-data';
import { memberAction, collectionAction, serializeAndPush } from 'ember-api-actions';
import { assign } from '@ember/polyfills';
const { attr, Model } = DS;
function mergeAttributes(attributes) {
let payload = this.serialize();
payload.data.attributes = assign(payload.data.attributes, attributes);
return payload;
}
export default Model.extend({
name: attr('string'),
ripen: memberAction({ path: 'doRipen' }),
info: memberAction({ path: 'info', type: 'get' }),
ripenAll: collectionAction({ path: 'ripenEverything' }),
getFresh: collectionAction({ path: 'fresh', type: 'get' }),
eat: memberAction({
path: 'doEat',
before: mergeAttributes,
after: serializeAndPush
}),
eatAll: collectionAction({
path: 'doEatAll',
before: mergeAttributes,
after: serializeAndPush })
});
// END-SNIPPET