Reputation: 2041
Obviously it's in client side memory, but what's keeping it there under the hood? LocalStorage? WebStorage?
Upvotes: 0
Views: 555
Reputation: 67469
It's just some Javascript variables.
Here's a tiny version of a Redux store:
function createStore(reducer) {
var state;
var listeners = []
function getState() {
return state
}
function subscribe(listener) {
listeners.push(listener)
return function unsubscribe() {
var index = listeners.indexOf(listener)
listeners.splice(index, 1)
}
}
function dispatch(action) {
state = reducer(state, action)
listeners.forEach(listener => listener())
}
dispatch({})
return { dispatch, subscribe, getState }
}
So, state
is literally just a variable that points to whatever your reducer function returned.
Upvotes: 5