Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Davzie\ProductCatalog\Entities;
use Validator;
use Input;
use Illuminate\Support\MessageBag;
use Exception;
use App;
class Base {
@glendaviesnz
glendaviesnz / app.component.ts
Created September 22, 2016 21:18
Angular 2 app root component with dynamic first child
import { Component, Input, ElementRef } from '@angular/core';
@Component({
selector: 'app',
template: '<dynamic-component [componentName]="componentName"></dynamic-component>'
})
export class AppComponent {
public componentName: string;
@glendaviesnz
glendaviesnz / dynamic-component.ts
Created September 22, 2016 21:19
Angular 2 dynamic component
import { Component, Input, ViewChild, OnInit, ComponentFactoryResolver, ComponentFactory, ComponentRef } from '@angular/core';
import { ViewContainerRef } from '@angular/core';
import { SitesList } from './sites/sites-list.component';
import { UserList } from './users/user-list.component'
const components = {
SitesList,
UserList
}
@glendaviesnz
glendaviesnz / ngrx_actions.ts
Created February 28, 2017 02:00 — forked from ghetolay/ngrx_actions.ts
Pattern to build actions for ngrx
interface Action<T> {
type: T;
}
interface PayloadAction<T, R> {
readonly type: T;
payload: R;
}
interface ActionFactory<T> {
@glendaviesnz
glendaviesnz / ngrx_actions.ts
Created February 28, 2017 02:00 — forked from ghetolay/ngrx_actions.ts
Pattern to build actions for ngrx
interface Action<T> {
type: T;
}
interface PayloadAction<T, R> {
readonly type: T;
payload: R;
}
interface ActionFactory<T> {
describe('formPanel: FormFilterStore', function () {
it('Should generate new filters when formFilterChangeStream emits', function () {
jasmine.Clock.useMock();
formFilterStore.currentFormFiltersStream.subscribe(function(filters){
expect(filters.CQLFilter).toEqual('A new Cql Filter');
expect(filters.APIFilter).toEqual('[A new Api filter]');
});
@glendaviesnz
glendaviesnz / example-test.spec.ts
Created May 16, 2018 23:54
Helper for testing Angular Material Select Menu changes in Unit Tests
import { ComponentFixture, TestBed, async, inject, fakeAsync, flush } from '@angular/core/testing';
import {
MatCheckboxModule,
MatSelectModule
} from '@angular/material';
import { By } from '@angular/platform-browser';
import { SelectMenuTestHelper } from './select-menu-test.helper';
describe('SelectOptionComponent', () => {
@glendaviesnz
glendaviesnz / DeclarativeFormStyle.jsx
Last active May 26, 2018 02:46
Rxjs based React forms blog post
<EasyForm onsubmit="this.onFormSubmit">
<label>
First name
<input name="firstName" />
</label>
<label>
Last name
<input name="lastName" />
</label>
<input name="newsletterSub" type="checkbox" />
@glendaviesnz
glendaviesnz / RecursiveRefs.jsx
Created May 26, 2018 06:52
Recursive method to add refs to nested form elements in props.children
class EasyForm extends React.Component {
fieldRefs = []
fieldTypes = ['input', 'button', 'textarea'];
addRefsToChildren(children) {
let childPropsChildren;
const newChildren = React.Children.map(children, child => {
if (child.props && child.props.children ) {
childPropsChildren = this.addRefsToChildren(child.props.children);
@glendaviesnz
glendaviesnz / state-machine.ts
Last active June 1, 2018 02:33
Extension of NgRx ActionsSubject to manage Component State
@Injectable()
export class ComponentStateMachine extends ActionsSubject {
constructor() {
super();
}
public next(action: any) {
// add all your state machine magic here ....
if (isValidAction) {
super.next(action);