Skip to content

Instantly share code, notes, and snippets.

View ronnyek's full-sized avatar
💭
All Systems Nominal

Weston ronnyek

💭
All Systems Nominal
  • San Luis Obispo Area, California
View GitHub Profile
@ronnyek
ronnyek / feature1.module.ts
Last active July 8, 2020 17:00
Routing Ideas
@Route('/feature1/', {lazy: true})
@DefaultRoute('/feature1/users')
@NgModule({
declarations: [
UsersComponent
]
})
export class Feature1Module{
}
expect('.someDiv').toHaveClass('some class')
expect('.someDiv').toHaveText('some text')
expect('.someDiv').toBeChecked()
expect('.someDiv').toBeDisabled()
host.dispatchMouseEvent('.someDiv', 'click'); //somediv could be an existing element as well
host.dispatchKeyboardEvent('.someDiv', 'keydown', 'p');
export class SomeOtherComponent extends Mixin1(Mixin2(Unsubscribable(ComponentRoot))){
//...
}
export class SomeNewComponent extends Unsubscribable(ComponentRoot){
constructor(someObservable: Observable){
super(); //must be called because we extend base
someObservable
.pipe(takeUntil(this.unsubscribeAll))
.subscribe(value => {//do something with value});
}
}
export function Unsubscribable<T extends Constructor<{}>>(Base: T) {
class WithUnsubscribable extends Base implements OnDestroy {
protected unsubscribeAll: Subject<any> = new Subject();
ngOnDestroy(): void {
this.unsubscribeAll.next();
this.unsubscribeAll.complete();
}
}
// default basic constructor required for mixins themselves
export type Constructor<T> = new (...args: any[]) => T;
// base class basically used as a placeholder
export class ComponentRoot {
}
export class SomeComponent {
property: string;
...
someMethod(){
this.property = 'new value';
this.cdr.markForCheck();
}
constructor(private cdr: ChangeDetectorRef){ }
}
import { Component, Input } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
@Component({
selector: 'some-component',
template: ``
})
export class SomeComponent {
private _showLabel: boolean; //set a default val if necessary
@Input()
using LinqToDb;
namespace Demo {
public class Repository {
public UserWithProfile GetUserById(int id){
using (var db = GetDataContext(...))
{
return db.Users.FirstOrDefault(x=>x.Id == id);
}
}