Skip to content

Instantly share code, notes, and snippets.

Avatar

Romke van der Meulen RomkeVdMeulen

View GitHub Profile
@RomkeVdMeulen
RomkeVdMeulen / aurelia_vm_class_naming_convention.ts
Created Dec 9, 2019
Override the naming convention for View Model class names in Aurelia
View aurelia_vm_class_naming_convention.ts
import {HtmlBehaviorResource} from "aurelia-framework";
const orig: (...args: any[]) => any = HtmlBehaviorResource.convention;
HtmlBehaviorResource.convention = function(name: string, ...args: any[]) {
if (name.endsWith("Component")) {
name = name.replace(/Component$/, "CustomElement");
}
if (name.endsWith("Route")) {
name = name.replace(/Route$/, "CustomElement");
}
@RomkeVdMeulen
RomkeVdMeulen / request-context.ts
Created Aug 2, 2019
Context wrapper for async (request) operations with some useful state flags
View request-context.ts
/**
* Vormt een wrapper om async operaties waarin de staat van de operatie
* bijgehouden wordt.
*/
export class AsyncContext {
bezig = false;
mislukt = false;
geslaagd = false;
@RomkeVdMeulen
RomkeVdMeulen / advanced-object-types.ts
Created Aug 2, 2019
Some advanced partial object type definitions for TypeScript
View advanced-object-types.ts
// tslint:disable:align ban-types
export type DeepPartial<T> =
T extends Array<infer U> ? DeepPartialArray<U> :
T extends ReadonlyArray<infer V> ? DeepPartialReadonlyArray<V> :
T extends object ? DeepPartialObject<T> :
T;
export type DeepPartialNoMethods<T> =
T extends Array<infer U> ? DeepPartialArrayNoMethods<U> :
T extends ReadonlyArray<infer V> ? DeepPartialReadonlyArrayNoMethods<V> :
@RomkeVdMeulen
RomkeVdMeulen / confirm-unload.ts
Last active Aug 27, 2019
Decorator for Aurelia routes that ask the user to confirm when unloading with unsaved changes
View confirm-unload.ts
import {decorateMethod} from "util/objects";
export interface ConfirmUnloadConfig {
hasUnsavedChanges(): boolean;
getUnloadConfirmMessage(): string;
}
export function confirmUnload(viewModel: any): any {
decorateMethod(viewModel, "attached", function attached() {
const self: ConfirmUnloadConfig = this;
@RomkeVdMeulen
RomkeVdMeulen / app.html
Last active Aug 1, 2019 — forked from jsobell/app.html
Aurelia Child Router with Parameters
View app.html
<template>
<router-view></router-view>
</template>
@RomkeVdMeulen
RomkeVdMeulen / 0_src-numbered-textarea.html
Last active Aug 17, 2018
An Aurelia component showing a textarea with line-numbers and locked height
View 0_src-numbered-textarea.html
<template>
<div class="element-wrapper ${invoerFocus ? 'focus' : ''} ${invoerRegels.length >= 10 ? 'vol' : ''}"
e2e="wrapper" data-focus.bind="invoerFocus">
<ol class="regelnummers" ref="regelnummers" e2e="regelnummer-wrapper" css="height: ${hoogte + 24}px">
<li repeat.for="i of aantalGetoondeRegels" e2e="regelnummer"
data-actief.bind="invoerRegels.length > i && invoerRegels[i].trim() !== ''"
class="regelnummer ${invoerRegels.length > i && invoerRegels[i].trim() !== '' ? 'actief' : ''}"></li>
</ol>
<div class="invoer-wrapper">
<textarea value.bind="invoer" ref="invoerElement" e2e="invoer"
@RomkeVdMeulen
RomkeVdMeulen / analytics.ts
Created Feb 22, 2018
Aurelia Custom Attribute for registering events with Google Universal Analytics
View analytics.ts
import {autoinject, bindable} from "aurelia-framework";
declare const ga: (
command: "send",
type: "event",
category?: string,
action?: string,
label?: string,
) => void;
View operationqueue.ts
interface OperationQueue {
queue: Promise<void>;
}
export function makeOperationQueue(): OperationQueue {
return {queue: Promise.resolve()};
}
export function queuedOperation(operationQueue: OperationQueue) {
return function(_target: any, _key: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) {
View autocast.ts
export function autocast<T>(type: {new (): T}) {
return function(target: any, key: string) {
makeAutocast(target, key, (newVal: any) => {
if (newVal === undefined) {
return undefined;
}
if (newVal instanceof type) {
return newVal;
}
return Object.assign(new type(), newVal);
@RomkeVdMeulen
RomkeVdMeulen / init.ts
Last active May 10, 2018
@init / @waitOnInit TypeScript method decorators
View init.ts
const INIT_METHODS = new Map<any, string[]>();
type InitMethodDescriptor = TypedPropertyDescriptor<() => void>
| TypedPropertyDescriptor<() => Promise<void>>;
export function init(target: any, key: string, _descriptor: InitMethodDescriptor) {
if (!INIT_METHODS.has(target)) {
INIT_METHODS.set(target, []);
}
INIT_METHODS.get(target)!.push(key);