Skip to content

Instantly share code, notes, and snippets.

Avatar

Jon Pitcherella jonpitch

View GitHub Profile
@jonpitch
jonpitch / new-build-notifier.js
Created Sep 28, 2018
new build notifier - component - medium
View new-build-notifier.js
import Component from '@ember/component';
import layout from '../templates/components/new-build-notifier';
import { MDCSnackbar } from '@material/snackbar';
import { inject as service } from '@ember/service';
import { set } from '@ember/object';
import { task, timeout } from 'ember-concurrency';
import config from 'ember-get-config';
import { isEmpty } from '@ember/utils';
export default Component.extend({
@jonpitch
jonpitch / sw-registration.js
Created Sep 28, 2018
new build notification - service worker registration - medium
View sw-registration.js
import { addSuccessHandler } from 'ember-service-worker/service-worker-registration';
window.isUpdateAvailable =
'Promise' in window
? new Promise(function(resolve) {
addSuccessHandler(function(reg) {
reg.onupdatefound = function() {
const { installing } = reg;
installing.onstatechange = function() {
if (installing.state === 'activated') {
View new-build-notifier.hbs
<div class="mdc-snackbar mdc-snackbar--align-start" aria-live="assertive" aria-atomic="true" aria-hidden="true">
<div class="mdc-snackbar__text"></div>
<div class="mdc-snackbar__action-wrapper">
<button type="button" class="mdc-snackbar__action-button"></button>
</div>
</div>
View asset-map.js
// app/initializers/asset-map.js
import Ember from 'ember';
export function initialize(application) {
let assetMap = Ember.Object.extend();
application.register('impact:assets', assetMap);
application.inject('component:i18n-image', 'assets', 'impact:assets');
}
@jonpitch
jonpitch / demo.json
Created Aug 29, 2016
ember-i18n-json
View demo.json
// app/locales/en/translations.json
{
"app": {
"hello": "Hello"
}
}
// app/locales/es/translations.json
{
"app": {
View demo.js
// app/locales/en/translations.js
export default {
app: {
hello: 'Hello'
}
}
// app/locales/es/translations.js
export default {
app: {
@jonpitch
jonpitch / translate.php
Created Aug 26, 2016
Translation config
View translate.php
<?php
/**
* Translation definitions of what data is pushed to Crowdin.
* The languages table drives what languages are supported.
*
* Expected format:
* 'base table name' => [
* 'tl' => 'the translation content table',
* 'path' => 'where the content should live in Crowdin'
@jonpitch
jonpitch / ember-page.js
Created Jul 28, 2016
write better ember tests - ember page object
View ember-page.js
// page.js
import PageObject, {
text,
isVisible
} from 'frontend/tests/page-object';
export default PageObject.create({
// some button
button: {
scope: '#some-button-id',
@jonpitch
jonpitch / basic-page-object.js
Created Jul 28, 2016
write better ember tests - page object
View basic-page-object.js
// without page object - bad
test('here is a test that does not use a page object', function(assert) {
this.render(hbs`{{my-component}}`);
const $button = this.$('#some-button-id');
const $description = this.$('p');
assert.ok($button.is(':visible'), 'I see the button');
assert.equal($description.text().trim(), 'Some text', 'The text is shown correctly');
});
@jonpitch
jonpitch / assertion-message.js
Created Jul 28, 2016
write better ember tests - be verbose
View assertion-message.js
test('this is a dummy test', function(assert) {
const a = true;
const b = true;
// a developer can quickly scan these messages to understand what
// needs to happen and why.
assert.ok(a, 'A is true when X');
assert.equal(a, b, 'A and B are equal when X');
});