-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add mixins for store and model
This allows for better composition, and to not have Ember Data as a dependency
- Loading branch information
Ilya Radchenko
committed
Feb 25, 2017
1 parent
ae68e9a
commit 4425755
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Ember from 'ember'; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Ember.Mixin.create({ | ||
save() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
reload() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
destroyRecord() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
wrap: task(function * (promise) { | ||
let result = yield promise; | ||
return result; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Ember from 'ember'; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default Ember.Mixin.create({ | ||
findAll() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
query() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
findRecord() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
queryRecord() { | ||
let promise = this._super(...arguments); | ||
return this.get('wrap').perform(promise); | ||
}, | ||
|
||
wrap: task(function * (promise) { | ||
let result = yield promise; | ||
return result; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
import TaskModelMixin from 'ember-data-tasks/mixins/task-model'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Mixin | task model'); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
let TaskModelObject = Ember.Object.extend(TaskModelMixin); | ||
let subject = TaskModelObject.create(); | ||
assert.ok(subject); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
import TaskStoreMixin from 'ember-data-tasks/mixins/task-store'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Mixin | task store'); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
let TaskStoreObject = Ember.Object.extend(TaskStoreMixin); | ||
let subject = TaskStoreObject.create(); | ||
assert.ok(subject); | ||
}); |