redux-behavior-subject
Version:
Create simple store with behavior subject and track changes by demand with [Redux DevTools](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en) for better performance only when you set to debug (set session s
34 lines (33 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const redux_extension_1 = require("./redux-extension");
const utils_1 = require("./utils");
const consts_1 = require("./consts");
class ReduxBehaviorSubject {
constructor(value, options) {
this.bs$ = new rxjs_1.BehaviorSubject(value);
this.options = Object.assign({}, this.getDefaultOptions(), options);
}
set(value, action) {
const val = value && utils_1.shallowCopy(value);
if (this.options.isDevMode) {
const updatedBy = action || utils_1.callerNameByException() || "unknown";
redux_extension_1.reduxExtension.sendAction(updatedBy, this.options.entityName, val);
}
return this.bs$.next(val);
}
get() {
return this.bs$.asObservable();
}
getValue() {
return this.bs$.getValue();
}
getDefaultOptions() {
return {
entityName: Math.random().toString(36),
isDevMode: sessionStorage.getItem(consts_1.RBS_SESSION_TOKEN_ENABLE_DEBUG) === "true"
};
}
}
exports.ReduxBehaviorSubject = ReduxBehaviorSubject;