import { Subject, from } from 'rxjs';
import { scan, startWith, flatMap } from 'rxjs/operators';
import { isObservable } from './rx-util';
import { Util } from '../util/util';
const action$ = new Subject();
export const createStore = (reducer, initState = { timestamp: Util.getTimeStamp(), id: Util.getUUID() }) => action$.pipe(flatMap((action) => isObservable(action) ? action : from([action])), startWith(initState), scan(reducer));
// higher order function to send actions to the stream
export const actionCreator = (func) => (...args) => {
    const action = func.call(null, ...args);
    action$.next(action);
    if (isObservable(action.payload))
        action$.next(action.payload);
    return action;
};
//# sourceMappingURL=rx-redux.js.map