Skip to content

Instantly share code, notes, and snippets.

@chrismllr
chrismllr / controllers.application\.js
Last active June 16, 2020 21:25
ember-validation-state
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import validationState, { validate } from 'ember-validation-state';
import { task } from 'ember-concurrency-decorators';
import { timeout } from 'ember-concurrency';
const validators = {
username: [validate('presence', { presence: true })],
password: [
@chrismllr
chrismllr / arg.js
Created September 18, 2019 14:48
ember @arg decorator
/**
* @description Declares a one-way read-only component property, which reads from `this.args`
* and falls back to default declared on the class property.
* @export
* @returns {ClassProperty}
*/
export default function arg(target, property, descriptor) {
let _value;
if (descriptor.initializer !== null) {
@chrismllr
chrismllr / poll.js
Last active May 9, 2019 23:20
ember-concurrency composable task for long poll functionality
import { task, timeout } from 'ember-concurrency';
import Config from 'app/config/environment';
const DEFAULT_POLL_MS = 20000; // 20 sec
export function pollTask(_requestTask, pollMs = DEFAULT_POLL_MS) {
const taskProperty = task(_requestTask).restartable();
const ogTaskFn = taskProperty.taskFn;
taskProperty.taskFn = function*(...args) {
@chrismllr
chrismllr / .block
Last active April 19, 2019 15:10
bubble scatter
license: mit
@chrismllr
chrismllr / a-controller.js
Created February 11, 2019 17:47
Confirm action - Usage
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
confirmAction: service(),
api: service(),
async deleteRecord(record) {
try {
const result = await this.confirmAction.ask({
@chrismllr
chrismllr / application.hbs
Last active February 11, 2019 15:53
Confirm action - Template
{{! The rest of your application template }}
{{#if confirmAction.showPrompt}}
<ModalDialog>
<h2>{{confirmAction.title}}</h2>
<p>{{confirmAction.message}}</p>
<div class="flex justify-end p--default">
<button {{action "cancel" target=this.confirmAction}}>
Cancel
@chrismllr
chrismllr / confirm-action.js
Created February 11, 2019 15:37
Confirm action service
import Service from '@ember/service';
import { setProperties } from '@ember/object';
import { defer } from 'rsvp';
export default Service.extend({
showPrompt: false,
title: null,
message: null,
_deferred: null,
<Input
shouldShowLabel={false}
// labelText=”Username” - Still don't need this
value={this.state.username}
inputStyle={{ padding: ‘12px’ }}
wrapperStyle={{ marginBottom: ‘30px’ }}
onChange={this.updateUsername}
/>
<Input
shouldShowLabel={false}
// labelText="Username" - Don't need this anymore
value={this.state.username}
style={{ marginBottom: '30px' }}
onChange={this.updateUsername}
/>
<Input
labelText="Username"
value={this.state.username}
onChange={this.updateUsername}
/>