-
-
Save nightire/b959ece0dd60c6a23c78565bd27feaf4 to your computer and use it in GitHub Desktop.
SkeletonScreen Example
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, computed } = Ember; | |
const BlogPostCardComponent = Component.extend({ | |
classNames: ['blog-post-card', 'card'], | |
classNameBindings: ['disabled::clickable'], | |
click() { | |
if (!this.get('disabled')) { | |
this.get('viewPost')(this.get('post')); | |
} | |
}, | |
humanDate: computed('post.createdAt', { | |
get() { | |
let createdAt = this.get('post.createdAt'); | |
let day = createdAt.getDate(); | |
let month = createdAt.getMonth() + 1; | |
let year = createdAt.getFullYear(); | |
return `${month}/${day}/${year}`; | |
} | |
}), | |
isoDate: computed('post.createdAt', { | |
get() { | |
return this.get('post.createdAt').toISOString(); | |
} | |
}) | |
}); | |
BlogPostCardComponent.reopenClass({ | |
positionalParams: ['post'] | |
}); | |
export default BlogPostCardComponent; |
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 } = Ember; | |
export default Component.extend({ | |
classNames: ['loading-card', 'card'], | |
}); |
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 { Controller, computed: { and, empty, not, or, reads } } = Ember; | |
export default Controller.extend({ | |
queryParams: ['page', 'fail'], | |
page: 1, | |
fail: false, | |
posts: or('model.{currentWrapper,previousWrapper}.content'), | |
metadata: reads('posts.meta'), | |
isLoading: reads('model.currentWrapper.isPending'), | |
error: reads('model.currentWrapper.reason'), | |
hasNoPosts: empty('posts'), | |
hasPosts: not('hasNoPosts'), | |
showLoadingMessage: and('{hasPosts,isLoading}'), | |
showSkeleton: and('{hasNoPosts,isLoading}'), | |
actions: { | |
viewPost(post) { | |
this.transitionToRoute('post', post); | |
} | |
} | |
}); |
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 { Controller, computed, computed: { reads } } = Ember; | |
export default Controller.extend({ | |
post: reads('model'), | |
isoDate: computed('post.createdAt', { | |
get() { | |
return this.get('post.createdAt').toISOString(); | |
} | |
}) | |
}); |
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 Response from 'ember-cli-mirage/response'; | |
const { random } = Math; | |
export default function() { | |
this.resource('blog-posts', { except: ['index'] }); | |
this.get('blog-posts', function(schema, request) { | |
console.log(request.queryParams); | |
return request.queryParams.fail === "true" | |
? new Response(500, { 'Content-Type': 'text/html' }, 'Fake Server Error') | |
: this.serialize(schema.blogPosts.all()); | |
}, { timing: 2000 }); | |
} |
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, association, faker } from 'ember-cli-mirage'; | |
export default Factory.extend({ | |
title: faker.hacker.phrase, | |
createdAt: faker.date.past, | |
author: faker.name.findName | |
}); |
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) { | |
server.createList('blog-post', 10, {author: 'Zelda'}); | |
server.createList('blog-post', 8, {author: 'Link'}); | |
server.createList('blog-post', 9, {author: 'Gannondorf'}); | |
} |
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 ApplicationSerializer from './application'; | |
const { ceil } = Math; | |
export default ApplicationSerializer.extend({ | |
serialize(response, req) { | |
let json = ApplicationSerializer.prototype.serialize.apply(this, arguments); | |
let posts = json.data; | |
let total = posts.length; | |
let page = parseInt(req.queryParams.page, 10) || 1; | |
let size = parseInt(req.queryParams.size, 10) || 10; | |
let start = (page - 1) * size; | |
let end = start + size; | |
if (start < 0) { | |
json.data = []; | |
} else { | |
json.data = posts | |
.sortBy('attributes.created-at') | |
.reverse() | |
.slice(start, end); | |
} | |
return this.attachMetadata(json, { page, size, total }); | |
}, | |
attachMetadata(json, { page, size, total }) { | |
let pages = ceil(total / size); | |
json.meta = { page, pages, total }; | |
return json; | |
} | |
}); |
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"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
title: attr('string'), | |
createdAt: attr('date'), | |
author: attr('string') | |
}); |
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('post', { path: '/post/:id' }); | |
}); | |
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
import Ember from 'ember'; | |
const { Route, Object: EmObject, PromiseProxyMixin } = Ember; | |
const Wrapper = EmObject.extend(PromiseProxyMixin); | |
export default Route.extend({ | |
queryParams: { | |
page: { refreshModel: true }, | |
fail: { refreshModel: true, replace: true } | |
}, | |
model({ page, fail }) { | |
let promise = this.store.query('blog-post', { fail, page, size: 5 }); | |
let currentWrapper = Wrapper.create({ promise }); | |
let previousWrapper = this.get('previousWrapper'); | |
currentWrapper.then(() => this.set('previousWrapper', currentWrapper)); | |
currentWrapper.catch(() => {}); | |
return { currentWrapper, previousWrapper }; | |
} | |
}); |
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 } = Ember; | |
export default Route.extend({ | |
model(params) { | |
return this.store.findRecord('blog-post', params.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
num { | |
font-family: monospace; | |
} | |
.clickable { | |
cursor: pointer; | |
} | |
.post-list { | |
display: flex; | |
flex-wrap: wrap; | |
justify-content: center; | |
align-items: top; | |
} | |
.blog-post-card.clickable:hover { | |
background-color: #eee; | |
} | |
.blog-post-card, .loading-card { | |
width: 200px; | |
margin: 25px; | |
min-height: 200px; | |
} | |
.loading-card .card-content { | |
text-align: center; | |
} |
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.13.0", | |
"ENV": { | |
"ember-cli-mirage": { | |
"enabled": true | |
} | |
}, | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"hack_css": "https://cdnjs.cloudflare.com/ajax/libs/hack/0.8.0/hack.css", | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3", | |
"ember-cli-mirage": "0.4.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment