You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/_util/store/create.js

31 lines
554 B

export default function create(initialState) {
let state = initialState;
const listeners = [];
7 years ago
function setState(partial) {
state = { ...state, ...partial };
7 years ago
for (let i = 0; i < listeners.length; i++) {
listeners[i]();
7 years ago
}
}
function getState() {
return state;
7 years ago
}
function subscribe(listener) {
listeners.push(listener);
7 years ago
return function unsubscribe() {
const index = listeners.indexOf(listener);
listeners.splice(index, 1);
};
7 years ago
}
return {
setState,
getState,
subscribe,
};
7 years ago
}