init
This commit is contained in:
		
							
								
								
									
										42
									
								
								src/store.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/store.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| import { writable } from 'svelte/store'; | ||||
|  | ||||
| const store = () => { | ||||
| 	const state = { | ||||
| 		isLoggedIn: false | ||||
| 	}; | ||||
|  | ||||
| 	const { subscribe, set, update } = writable(state); | ||||
|  | ||||
| 	const methods = { | ||||
| 		init() { | ||||
| 			console.log('*: playerStore -> init()'); | ||||
| 			update((state) => { | ||||
| 				state.isLoggedIn = false; | ||||
| 				return state; | ||||
| 			}); | ||||
| 		}, | ||||
|  | ||||
| 		login() { | ||||
| 			update((state) => { | ||||
| 				state.isLoggedIn = true; | ||||
| 				console.log('login performed'); | ||||
| 				return state; | ||||
| 			}); | ||||
| 		}, | ||||
| 		logout() { | ||||
| 			update((state) => { | ||||
| 				state.isLoggedIn = false; | ||||
| 				return state; | ||||
| 			}); | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	return { | ||||
| 		subscribe, | ||||
| 		set, | ||||
| 		update, | ||||
| 		...methods | ||||
| 	}; | ||||
| }; | ||||
|  | ||||
| export default store(); | ||||
		Reference in New Issue
	
	Block a user