-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
127 additions
and
17 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
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
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,19 @@ | ||
export let objectAssign = Object.assign || function objectAssign(target) { | ||
'use strict'; | ||
if (target == null) { | ||
throw new TypeError('Cannot convert undefined or null to object'); | ||
} | ||
|
||
target = Object(target); | ||
for (var index = 1; index < arguments.length; index++) { | ||
var source = arguments[index]; | ||
if (source != null) { | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
} | ||
return target; | ||
}; |
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
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,32 @@ | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | ||
import buildServer from '../helpers/fake-album-server'; | ||
import assertDetails from '../helpers/assert-acceptance-details'; | ||
|
||
let server; | ||
|
||
moduleForAcceptance('Acceptance: Infinity Route - custom store route', { | ||
beforeEach() { | ||
server = buildServer(); | ||
this.customStore = this.application.__container__.lookup('service:custom-store'); | ||
for (let x = 0; x <= 5; x++) { | ||
this.customStore.push('custom-model', { id: x }); | ||
} | ||
}, | ||
afterEach() { | ||
server.shutdown(); | ||
delete this.customStore; | ||
} | ||
}); | ||
|
||
test('scott scott it works with custom store', function(assert) { | ||
visit('/custom-store'); | ||
|
||
andThen(() => { | ||
assertDetails(assert, { | ||
title: 'Listing Posts', | ||
listLength: 6, | ||
reachedInfinity: true | ||
}); | ||
}); | ||
}); |
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,6 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Object.extend({ | ||
name: '' | ||
}); | ||
|
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
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,10 @@ | ||
import Ember from 'ember'; | ||
const { Route, inject: { service } } = Ember; | ||
import InfinityRoute from 'ember-infinity/mixins/route'; | ||
|
||
export default Route.extend(InfinityRoute, { | ||
customStore: service(), | ||
model() { | ||
return this.infinityModel('custom-model', { store: 'customStore', storeFindMethod: 'findAll' }); | ||
} | ||
}); |
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,46 @@ | ||
import Ember from 'ember'; | ||
|
||
function factoryForType(type, store) { | ||
return Ember.getOwner(store)._lookupFactory('model:' + type); | ||
} | ||
|
||
function persistData(type, obj, customStore) { | ||
const persistentContainer = customStore.get('persistentContainer'); | ||
const Factory = factoryForType(type, customStore); | ||
const record = Factory.create(obj); | ||
const id = obj.id; | ||
if (persistentContainer[type]) { | ||
return persistentContainer[type].set(id, record); | ||
} | ||
persistentContainer[type] = new Map(); | ||
return persistentContainer[type].set(id, record); | ||
} | ||
|
||
export default Ember.Service.extend({ | ||
/** | ||
* holds all models by type | ||
* @property persistentContainer | ||
*/ | ||
persistentContainer: {}, | ||
/** | ||
* find objects by id | ||
* find method must return a promise so patching in a thennable w/ resolve | ||
* @method findAll | ||
* @param {String} type | ||
*/ | ||
findAll(type) { | ||
const containerObjs = this.get('persistentContainer')[type]; | ||
const content = Array.from(containerObjs.values()); | ||
const arrProxy = Ember.ArrayProxy.create({ content: Ember.A(content) }); | ||
return Ember.RSVP.resolve(arrProxy); | ||
}, | ||
/** | ||
* @method push | ||
* @param {String} type | ||
* @param {Object} obj | ||
*/ | ||
push(type, obj) { | ||
const hydrated = persistData(type, obj, this); | ||
return hydrated.get(obj.id); | ||
}, | ||
}); |
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,9 @@ | ||
<h2 id="posts-title">Listing Posts</h2> | ||
|
||
<ul class="test-list"> | ||
{{#each model as |post|}} | ||
<li>{{post.name}}</li> | ||
{{/each}} | ||
</ul> | ||
|
||
{{infinity-loader infinityModel=model}} |