JSFiddle - React, Tailwind, and code Playground
by amindunited
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.2/rxjs.umd.min.js"></script>
JavaScript
const BehaviorSubject = rxjs.BehaviorSubject;
const Subject = rxjs.Subject;
const scan = rxjs.operators.scan;
const map = rxjs.operators.map;
const initState = {
initState: true
};
const store = function (state = initState, reducers) {
let store$ ={}, actions = {};
for ( let reducer in reducers ) {
console.log(reducer, ':', reducers[reducer]);
}
return { store$, actions }
}
const reducers = {
};
const counterState = (newState) => {
let state = new Subject({
count: 0
})
let actions = {
increaseCount: () => {
// The key of the subject should be a variable
state.next({ count: (state.count += 1) });
return state;
},
decreaseCount: () => {
// The key of the subject should be a variable
state.next({ count: (state.count -= 1) })
}
}
return { state, actions };
}
const delayFn = (fn, delay) => {
setTimeout(fn, delay);
}
delayFn(() => {
counterState({}).state.subscribe((state) => { console.log('cnahe', state); });
console.log(counterState({}).actions.increaseCount())
}, 1000);
console.log('countermodule ', counterState({}));
console.log('store', store({}, reducers));