Skip to content

Instantly share code, notes, and snippets.

View gossi's full-sized avatar

Thomas Gossmann gossi

View GitHub Profile
@gossi
gossi / controllers.application\.js
Last active September 23, 2020 20:55
link modifier
import Controller from '@ember/controller';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@action
sayHello() {
console.log('hellooooooo');
}
Text w/ Date: <input type="text" inputmode="date">
Text w/ Numeric: <input type="text" inputmode="numeric">
Date: <input type="date">
@gossi
gossi / routes.application\.js
Last active May 30, 2020 15:46
no-controller
import Route from '@ember/routing/route';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ApplicationRoute extends Route {
@tracked foo = 'foo';
get bar() {
return `${this.foo} bar`;
}
@gossi
gossi / invoke-modifier.ts
Created December 5, 2019 09:25
{{on "click" ...}} vs {{invoke ...}} in regards to a11y
import Modifier from 'ember-modifier';
import { action } from '@ember/object';
interface InvokeArgs {
positional: [() => void],
named: {}
}
/**
* Invoke modifier:
@gossi
gossi / idea.md
Last active June 10, 2019 15:30
Concept: Ember Pages vs Route/Controller

In response to: https://gos.si/blog/ember-2019-reduce-complexity/

The idea in short

  1. Keep routing as-is
  2. Delete Route and Controller
  3. Replace with Page
  4. Page extends a glimmer component with special sauce to handle transitions and (query) params

Imagine the following layout (yeah, I like MU):

@gossi
gossi / input-event-demo.ts
Created May 3, 2019 12:50
Event Support: Demo
import { CompatibleInputEvent, IS_INPUT_SUPPORTED, normalizeInputEvent } from 'event-support';
// assuming `element` is a reference to an <input> elem
element.addEventListener('keydown', (event: KeyboardEvent) => {
const e = normalizeInputEvent(event);
if (!IS_INPUT_SUPPORTED || event.key.length > 1) {
handleEvent(e);
}
@gossi
gossi / normalize-input-event.ts
Created May 3, 2019 12:35
Event Support: normalize-input-event
export const normalizeInputEvent = function(event: KeyboardEvent | InputEvent): CompatibleInputEvent {
const e: CompatibleInputEvent = {
originalEvent: event
};
if (event instanceof KeyboardEvent) {
if (event.key === 'Backspace') {
e.inputType = 'deleteContentBackward';
e.navigationType = 'cursorLeft';
} else if (event.key === 'Delete') {
@gossi
gossi / compatible-input-event.ts
Created May 3, 2019 12:29
Event Support: CompatibleInputEvent
/**
* A normalized event from InputEvent and KeyboardEvent that works from ie11
* over modern browsers to android browsers (because that beast is worse than ie6)
*/
export interface CompatibleInputEvent {
data?: string;
inputType?: string;
navigationType?: string;
originalEvent: KeyboardEvent | InputEvent;
}
@gossi
gossi / is-input-supported.ts
Last active May 3, 2019 12:27
Event Support: is-input-supported
// Reference for InputEvent: https://w3c.github.io/input-events/#interface-InputEvent
export const IS_INPUT_SUPPORTED = (function() {
try {
// just kill browsers off, that throw an error if they don't know
// `InputEvent`
const event = new InputEvent('input', {
data: 'xyz',
inputType: 'deleteContentForward'
});
let support = false;
@gossi
gossi / README.md
Last active September 19, 2018 23:07
Ember Components Element API

Ember Components Element API

Background

I don't know what happens to be there first: Ember Components or Web Components. Actually doesn't matter because markup wise they are pretty identical. You can create a custom element to be used in your HTML markup, next to existing HTML elements. The components itself have to follow a specific naming scheme to distinguish them from regular HTML elements. They should either be written in <kebap-case> or <StudlyCase>. There is also a special syntax for attributes and arguments of ember and glimmer components (arguments are passed with the @ sigil). These are the visually distinction from components to regular HTML elements. From just watching at the markup it is possible to identify regular HTML elements and components, though it is not possible to say whether it is a webcomponent, an ember component or a glimmer component, e.g. <video-player id='abc'> could be either of that.

Over the past years, the DDAU pattern has been established as a data flow to pas