Skip to content

Instantly share code, notes, and snippets.

View phenomnomnominal's full-sized avatar
🥑
Hangry

Craig Spence phenomnomnominal

🥑
Hangry
View GitHub Profile
import * as tslib_1 from "tslib";
import { Component, Input } from "@angular/core";
import { Value, isBool, isNotNull } from "@trademe/ensure";
var HelloComponent = (function () {
function HelloComponent() { }
tslib_1.__decorate([
Value(isBool, isNotNull),
Input(),
tslib_1.__metadata("design:type", Boolean)
import { Component, Input } from '@angular/core';
import { Value, isBool, isNotNull } from '@trademe/ensure';
@Component({
selector: 'hello'
// ...
})
export class HelloComponent {
@Value(isBool, isNotNull) @Input()
public primary: boolean;
import { Component, Input } from '@angular/core';
import { isBool } from './is-bool';
@Component({
// ...
})
export class HelloComponent {
@isBool() @Input()
public primary: boolean;
}
@phenomnomnominal
phenomnomnominal / is-bool.ts
Created May 29, 2019 19:24
A decorator that fixes boolean input values
const VALUE_KEY = '__value_';
export function isBool (): PropertyDecorator {
return (target: any, propertyKey: string) => {
Object.defineProperty(target, propertyKey, {
get: function () {
return this[`${VALUE_KEY}${propertyKey}`];
},
set: function (value) {
this[`${VALUE_KEY}${propertyKey}`] = value != null && `${value}` !== 'false';
import { Component, Input } from '@angular/core';
@Component({
// ...
})
export class HelloComponent {
private _primary: boolean;
@Input() get primary (): boolean {
return this._primary;
}
@phenomnomnominal
phenomnomnominal / property-and-method.js
Created May 29, 2019 17:46
Example of property and method decorator-like functions
function PropertyDecorator (propertyOptions) {
// Modify the property in some way:
return propertyDescriptor;
}
function MethodDecorator (methodOptions) {
// Modify the method in some way:
return methodDescriptor;
}
@phenomnomnominal
phenomnomnominal / typescript-decorators.ts
Created May 29, 2019 15:37
Examples of current TypeScript decorator syntax
@ClassDecorator()
class MyClass {
@PropertyDecorator()
public myProperty: boolean = true;
@MethodDecorator()
public myMethod(): boolean {
return this.myProperty;
};
}
@phenomnomnominal
phenomnomnominal / property-and-method-idea.js
Last active May 29, 2019 15:41
Examples of property and method decorator-like functions
function PropertyDecorator (property) {
// Modify the property in some way:
return property;
}
function MethodDecorator (method) {
// Modify the method in some way:
return method;
}
@phenomnomnominal
phenomnomnominal / class-decorator.js
Last active May 29, 2019 17:45
Example of a class decorator-like function
function Decorator (constructor) {
constructor.bang = 'boop!';
return constructor;
}
const MyClass = Decorator(class _MyClass { });
console.log(MyClass.bang);
<my-card>
<my-card-video
myCardHero
video="https://www.youtube.com/embed/cbP2N1BQdYc?controls=0">
</my-card-video>
<my-card-title>Cute cat videos!</my-card-title>
<my-card-details
myCardContents
price="1000000"
listed="09/06/2012">