function system(initialState, reduce, feedback) {
    return rx.defer(function () {
        var state = new rx.ReplaySubject(1);
        var scheduler = rx.queueScheduler;
        var events = feedback.map(function (x) { return x(state, scheduler); });
        var mergedEvent = rx.merge.apply(rx, events).pipe(observeOn_1.observeOn(scheduler));
        var eventsWithEffects = mergedEvent
            .pipe(scan_1.scan(reduce, initialState), tap_1.tap(function (x) {
            state.next(x);
        }), subscribeOn_1.subscribeOn(scheduler), startWith_1.startWith(initialState), observeOn_1.observeOn(scheduler));
        var hackOnSubscribed = rx.defer(function () {
            state.next(initialState);
            return rx.empty();
        });
        return rx.merge.apply(rx, [eventsWithEffects, hackOnSubscribed]).pipe(catchError_1.catchError(function (e) {
            dispatchError(e);
            return rx.throwError(e);
        }));
    });
}
function system(initialState, reduce, feedback) {
    return rx.defer(function () {
        var state = new rx.ReplaySubject(1);
        var scheduler = rx.queueScheduler;
        var events = feedback.map(function (x) { return x(state, scheduler); });
        var mergedEvent = rx.merge.apply(rx, events).pipe(observeOn_1.observeOn(scheduler));
        var eventsWithEffects = mergedEvent
            .pipe(scan_1.scan(reduce, initialState), tap_1.tap(function (x) {
            state.next(x);
        }), subscribeOn_1.subscribeOn(scheduler), startWith_1.startWith(initialState), observeOn_1.observeOn(scheduler));
        var hackOnSubscribed = rx.defer(function () {
            state.next(initialState);
            return rx.empty();
        });
        return rx.merge.apply(rx, [eventsWithEffects, hackOnSubscribed]).pipe(catchError_1.catchError(function (e) {
            dispatchError(e);
            return rx.throwError(e);
        }));
    });
}
function system ( initialState , reduce , feedback ) { return rx . defer ( function ( ) { var state = new rx . ReplaySubject ( 1 ) ; var scheduler = rx . queueScheduler ; var events = feedback . map ( function ( x ) { return x ( state , scheduler ) ; } ) ; var mergedEvent = rx . merge . apply ( rx , events ) . pipe ( observeOn_1 . observeOn ( scheduler ) ) ; var eventsWithEffects = mergedEvent . pipe ( scan_1 . scan ( reduce , initialState ) , tap_1 . tap ( function ( x ) { state . next ( x ) ; } ) , subscribeOn_1 . subscribeOn ( scheduler ) , startWith_1 . startWith ( initialState ) , observeOn_1 . observeOn ( scheduler ) ) ; var hackOnSubscribed = rx . defer ( function ( ) { state . next ( initialState ) ; return rx . empty ( ) ; } ) ; return rx . merge . apply ( rx , [ eventsWithEffects , hackOnSubscribed ] ) . pipe ( catchError_1 . catchError ( function ( e ) { dispatchError ( e ) ; return rx . throwError ( e ) ; } ) ) ; } ) ; }
The system simulation will be started upon subscription and stopped after subscription is disposed.

System state is represented as a `State` parameter.
Events are represented by the `Event` parameter.

@param initialState The initial state of the system.
@param reduce Calculates the new system state from the existing state and a transition event (system integrator, reducer).
@param feedback The feedback loops that produce events depending on the current system state.
@returns The current state of the system.
The system simulation will be started upon subscription and stopped after subscription is disposed .