Last active
April 26, 2021 14:23
-
-
Save rossjha/451cc377a1ff6c6d9e3ffc2349ad2cd8 to your computer and use it in GitHub Desktop.
Infinite Scroll
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
import Ember from 'ember'; | |
const { Route: EmberRoute } = Ember; | |
export default EmberRoute.extend({ | |
// Defaults | |
// Single line CP | |
// Multiline CP | |
// Private | |
// Lifecycle hooks | |
afterModel() { | |
this.replaceWith('users'); | |
} | |
}); |
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
import Ember from 'ember'; | |
const { Component: EmberComponent } = Ember; | |
export default EmberComponent.extend({ | |
// Defaults | |
// Single line CP | |
// Multiline CP | |
// Private | |
// Lifecycle hooks | |
}); |
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
import Ember from 'ember'; | |
const { Component: EmberComponent } = Ember; | |
const { computed } = Ember; | |
export default EmberComponent.extend({ | |
// Defaults | |
users: computed.alias('model') | |
// Single line CP | |
// Multiline CP | |
// Private | |
// Lifecycle hooks | |
}); |
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
export default function() { | |
this.timing = 400; | |
this.get('users'); | |
this.get('users', function(schema, request) { | |
let queryParams = request.queryParams; | |
let page = parseInt(queryParams.page); | |
let perPage = parseInt(queryParams.per_page); | |
let start = 1; | |
if (page !== 1) { | |
start = perPage + 1; | |
} | |
let end = start + perPage; | |
let users = schema.users.all().models; | |
let filtered = users.slice(start, end); | |
let data = { data: filtered.map(attrs => ( | |
{ type: 'users', id: attrs.id, attributes: attrs } | |
)), | |
meta: { | |
total_pages: users.length / perPage | |
} | |
}; | |
return data; | |
}); | |
this.get('users/: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
import { Factory, faker } from 'ember-cli-mirage'; | |
export default Factory.extend({ | |
'created-at': '2017-01-01T00:00:00.000Z', | |
'first-name'() { | |
return faker.name.firstName(); | |
}, | |
'last-name'() { | |
return faker.name.lastName(); | |
}, | |
email() { | |
return `${this['first-name'].toLowerCase()}.${this['last-name'].toLowerCase()}@acme.com`; | |
}, | |
picture() { | |
return faker.internet.avatar(); | |
}, | |
'updated-at': '2017-01-01T00:00:00.000Z', | |
'updated-by': 'admin.user', | |
name() { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
}); |
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
import { Model } from 'ember-cli-mirage'; | |
export default Model.extend({ | |
}); |
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
export default function(server) { | |
// added this line because global wasn't created otherwise. | |
let user = server.createList('user', 50); | |
} |
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
import { JSONAPISerializer } from 'ember-cli-mirage'; | |
export default JSONAPISerializer.extend({ | |
}); |
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
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
const { computed, get } = Ember; | |
export const schema = { | |
// Attributes | |
createdAt: attr('date', { | |
defaultValue() { | |
return new Date(); | |
} | |
}), | |
email: attr('string'), | |
firstName: attr('string'), | |
lastName: attr('string'), | |
picture: attr('string'), | |
updatedAt: attr('date', { | |
defaultValue() { | |
return new Date(); | |
} | |
}), | |
updatedBy: attr('string'), | |
// Associations | |
// Computed Properties | |
name: computed('firstName', 'lastName', function() { | |
return `${get(this, 'firstName')} ${get(this, 'lastName')}`; | |
}) | |
}; | |
export default Model.extend(schema); |
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
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('users'); | |
}); | |
export default Router; |
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
/* Layout */ | |
* { | |
box-sizing: border-box; | |
margin: 0; | |
padding: 0; | |
} | |
html, body { | |
color: #444; | |
font-family: 'Roboto', sans-serif; | |
font-size: 100%; | |
} | |
.container{ | |
max-width: 960px; | |
margin: 0 auto; | |
} | |
/* Type */ | |
h1{ | |
margin-bottom: 30px; | |
padding-bottom: 15px; | |
border-bottom: 1px solid #eee; | |
} | |
/* Lists */ | |
main ul{ | |
margin-left: 17px; | |
} | |
/* Table */ | |
table{ | |
border-collapse: collapse; | |
} | |
th, td{ | |
padding: 10px; | |
text-align: left; | |
border: 1px solid #eee; | |
} | |
/* Actions */ | |
[data-ember-action] { | |
cursor: pointer; | |
} | |
/* Nav */ | |
nav{ | |
margin-bottom: 30px; | |
padding: 15px; | |
background: #efefef; | |
} | |
nav a{ | |
text-decoration: none; | |
color: #333; | |
} | |
nav a.active{ | |
color: #000; | |
font-weight: 500; | |
} | |
nav ul li{ | |
display: inline-block; | |
text-transform: uppercase; | |
} | |
nav ul li:not(:first-child) { | |
margin-left: 20px; | |
} | |
/* Users */ | |
.User{ | |
border: 1px solid #ccc; | |
padding: 10px; | |
margin-bottom: 20px; | |
border-radius: 3px; | |
} | |
.User__picture img{ | |
border-radius: 50%; | |
width: 60px; | |
height: 60px; | |
} | |
.reached-infinity .loader{ | |
display: none; | |
} | |
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
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
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
import { module } from 'qunit'; | |
import startApp from '../helpers/start-app'; | |
import destroyApp from '../helpers/destroy-app'; | |
export default function(name, options = {}) { | |
module(name, { | |
beforeEach() { | |
this.application = startApp(); | |
if (options.beforeEach) { | |
options.beforeEach.apply(this, arguments); | |
} | |
}, | |
afterEach() { | |
if (options.afterEach) { | |
options.afterEach.apply(this, arguments); | |
} | |
destroyApp(this.application); | |
} | |
}); | |
} |
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
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
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
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = Ember.merge({rootElement: "#test-root"}, config.APP); | |
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; | |
Ember.run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
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
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
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
{ | |
"version": "0.10.4", | |
"ENV": { | |
"ember-cli-mirage": { | |
"enabled": true | |
} | |
}, | |
"EmberENV": { | |
"FEATURES": { | |
"ds-finder-include": true | |
} | |
}, | |
"options": { | |
"use_pods": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-data": "2.12.1", | |
"ember-template-compiler": "2.12.0" | |
}, | |
"addons": { | |
"ember-cli-mirage": "0.2.4", | |
"ember-infinity": "0.2.1" | |
} | |
} |
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
import Ember from 'ember'; | |
import InfinityRoute from 'ember-infinity/mixins/route'; | |
const { Route: EmberRoute } = Ember; | |
export default EmberRoute.extend(InfinityRoute, { | |
// Defaults | |
// Single line CP | |
// Multiline CP | |
// Private | |
// Lifecycle hooks | |
model() { | |
// Load pages of user model, starting from page 1, in groups of 12 | |
return this.infinityModel('user', { perPage: 10, startingPage: 1 }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment