Skip to content

Commit

Permalink
feat(timepicker): new timepicker implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Jun 13, 2017
1 parent d12593d commit acc4b2b
Show file tree
Hide file tree
Showing 17 changed files with 1,115 additions and 298 deletions.
16 changes: 16 additions & 0 deletions src/mini-ngrx/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface Action {
type: string;
payload?: any;
}

export type ActionReducer<T> = (state: T, action: Action) => T;

export { MiniState } from './state.class';
export { MiniStore } from './store.class';

/**
* sample usage class
*
*
*
*/
23 changes: 23 additions & 0 deletions src/mini-ngrx/state.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { Action, ActionReducer } from './index';
import { observeOn } from 'rxjs/operator/observeOn';
import { queue } from 'rxjs/scheduler/queue';
import { scan } from 'rxjs/operator/scan';

export class MiniState<T> extends BehaviorSubject<T> {
constructor(_initialState: T, actionsDispatcher$: Observable<Action>, reducer: ActionReducer<T>) {
super(_initialState);

const actionInQueue$ = observeOn.call(actionsDispatcher$, queue);
const state$ = scan.call(actionInQueue$, (state: T, action: Action) => {
if (!action) {
return state;
}

return reducer(state, action);
}, _initialState);

state$.subscribe((value: T) => this.next(value));
}
}
39 changes: 39 additions & 0 deletions src/mini-ngrx/store.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { Operator } from 'rxjs/Operator';
import { distinctUntilChanged } from 'rxjs/operator/distinctUntilChanged';

import { map } from 'rxjs/operator/map';
import { Action, ActionReducer } from './index';

export class MiniStore<T> extends Observable<T> implements Observer<Action> {

constructor(private _dispatcher: Observer<Action>,
private _reducer: ActionReducer<any>,
state$: Observable<any>) {
super();

this.source = state$;
}

select<R>(pathOrMapFn: (state: T) => R): Observable<R> {
const mapped$: Observable<R> = map.call(this, pathOrMapFn);

return distinctUntilChanged.call(mapped$);
}

lift<R>(operator: Operator<T, R>): MiniStore<R> {
const store = new MiniStore<R>(this._dispatcher, this._reducer, this);
store.operator = operator;

return store;
}

dispatch(action: Action) { this._dispatcher.next(action); }

next(action: Action) { this._dispatcher.next(action); }

error(err: any) { this._dispatcher.error(err); }

complete() {/*noop*/}
}
3 changes: 3 additions & 0 deletions src/old-timepicker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { TimepickerConfig } from './timepicker.config';
export { TimepickerComponent } from './timepicker.component';
export { TimepickerModule } from './timepicker.module';
Loading

0 comments on commit acc4b2b

Please sign in to comment.