Skip to content

Instantly share code, notes, and snippets.

Avatar

Rob Wormald robwormald

View GitHub Profile
View elements.ts
import { BrowserModule } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements';
import { NgModule, Injector, NgModuleFactory, NgModuleRef } from '@angular/core';
import { SomeService } from './service'
import { AppComponent } from './app.component';
import { DemoElementModule, DemoElement } from './demo-element'
import { DemoElementModuleNgFactory } from './demo-element.ngfactory'
View test.ts
import * as ng from '@angular/platform'
function todoAppState(state = {todos: [1,2,3]}, action = {type:''}){
switch (action.type) {
case 'ADD_TODO':
return {
todos: state.todos.concat((action as any).payload),
...state
}
default:
View deprecate.ts
//copied from https://github.com/jayphelps/core-decorators
const { defineProperty, getOwnPropertyDescriptor,
getOwnPropertyNames, getOwnPropertySymbols } = Object;
export function isDescriptor(desc) {
if (!desc || !desc.hasOwnProperty) {
return false;
}
View test.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.lit = {})));
}(this, (function (exports) { 'use strict';
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
View enums.ts
interface Action {
type: string;
}
enum UserActions {
ADD_USER = 'ADD_USER',
DELETE_USER = 'DELETE_USER'
}
View testing.ts
describe(‘My Effects’, () => {
let effects: MyEffects;
let actions: Observable<any>;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
MyEffects,
provideMockActions(() => actions),
// other providers
View app.module.ts
@NgModule({
imports: [
StoreModule.forRoot(appReducers),
EffectsModule.forRoot([SourceA, SourceB]),
RouterModule.forRoot([
{ path: ‘lazy’, loadModule: ./lazy.module#LazyModule’ }
])
]
})
export class AppModule { }
View add-drama.ts
import {InjectionToken} from '@angular/core'
import {Http} from '@angular/http'
import {Observable} from 'rxjs/Rx'
//simple fn
export function AddDrama(value:string){
return `${value}!!!`
}
export const AddDramaProvider = {
View custom-element.ts
//hacked up view engine parts
import {ComponentFactory, ComponentRef} from './core/linker/component_factory';
import {ErrorHandler} from './core/error_handler';
import {Injector} from './core/di/injector';
import {NgModuleRef} from './core/linker/ng_module_factory';
import {RendererFactory2} from './core/render/api';
import {Sanitizer} from './core/security';
import {initServicesIfNeeded} from './core/view/index';
import {SimpleRendererFactory} from './core/renderer';
View input.ts
import {NgModule, Component} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'demo-app',
template: `
<h1>hello {{name}}</h1>
`
})
export class DemoApp {