Created
July 3, 2020 08:24
-
-
Save allinne/aaa6e0d014244f412ebf4be4f7499bac to your computer and use it in GitHub Desktop.
findAll
This file contains hidden or 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
import DS from 'ember-data'; | |
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; | |
import fakeAPI from '../fake-api'; | |
export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { | |
async findAll() { | |
await new Promise((resolve) => { | |
new Ember.RSVP.Promise(function(resolve, reject) { | |
fakeAPI.get().then((response) => { | |
Ember.run(null, resolve, response); | |
}); | |
}); | |
return { | |
data: [], | |
included: [], | |
}; | |
}, | |
}); |
This file contains hidden or 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
import Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
reloadModel() { | |
this.store.findAll('video', { reload: true }); | |
} | |
} |
This file contains hidden or 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
export default { | |
data: [], | |
post(payload) { | |
console.log('The "API" just received a POST request'); | |
// Pretend data was persisted at the API. | |
let updatedPayload = {}; | |
updatedPayload.title = payload.title; | |
updatedPayload.id = getRandomId(); | |
this.data.push(updatedPayload); | |
return new Ember.RSVP.Promise((resolve, reject) => { | |
resolve(updatedPayload); | |
}); | |
}, | |
get() { | |
return new Ember.RSVP.Promise((resolve, reject) => { | |
setTimeout(resolve(this.data), 3000); | |
}); | |
} | |
}; | |
function getRandomId() { | |
let min = Math.ceil(0); | |
let max = Math.floor(1000000000); | |
return Math.floor(Math.random() * (max - min)) + min; | |
} |
This file contains hidden or 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
import Model from 'ember-data/model'; | |
import DS from 'ember-data'; | |
/* | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
*/ | |
export default class extends Model { | |
title: DS.attr('string'), | |
} |
This file contains hidden or 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
import Route from '@ember/routing/route'; | |
export default Route.extend({ | |
model() { | |
return this.store.findAll('video'); | |
} | |
}); |
This file contains hidden or 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.12.2", | |
"ember-template-compiler": "3.12.2", | |
"ember-testing": "3.12.2" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.12.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment