import { Subject, from } from 'rxjs';
import { scan, startWith, flatMap } from 'rxjs/operators';
import { RxUtil } 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) => RxUtil.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 (RxUtil.isObservable(action.payload))
        action$.next(action.payload);
    return action;
};
// todo: dispatch?
// export const dispatch = ({action, payload})  => {
//     const action = action.call(null, ...args);
//     // return action;
// };
//# sourceMappingURL=rx-redux.js.map