"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var rx_util_1 = require("./rx-util");
var util_1 = require("../util/util");
var action$ = new rxjs_1.Subject();
exports.createStore = function (reducer, initState) {
    if (initState === void 0) { initState = { timestamp: util_1.Util.getTimeStamp(), id: util_1.Util.getUUID() }; }
    return action$.pipe(operators_1.flatMap(function (action) { return rx_util_1.RxUtil.isObservable(action) ? action : rxjs_1.from([action]); }), operators_1.startWith(initState), operators_1.scan(reducer));
};
// higher order function to send actions to the stream
exports.actionCreator = function (func) { return function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    var action = func.call.apply(func, [null].concat(args));
    action$.next(action);
    if (rx_util_1.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