import { initGlobalState, MicroAppStateActions } from 'qiankun';

const state = JSON.parse(window.localStorage.getItem('state')) || {
	token: null,
	theme: null,
}
console.log(state)
const actions = initGlobalState(state)
actions.onGlobalStateChange((state, prev) => {
	// state: 变更后的状态; prev 变更前的状态
	window.localStorage.setItem('state',JSON.stringify(state))
	state = state
	console.log(state, prev, '123123123');
});
const setToken = ((token) => {
	actions.setGlobalState({ ...state, token: token })
})
const setTheme = ((theme) => {
	actions.setGlobalState({ ...state, theme: theme })
})

const getAll = () =>{
	return JSON.parse(window.localStorage.getItem('state')) || state
}
export {
	setToken,
	setTheme,
	getAll
}