From 9d1580dcd6300eca95a6ce69da87f6395e3092a6 Mon Sep 17 00:00:00 2001 From: Me Date: Tue, 29 Nov 2022 14:54:58 +0100 Subject: [PATCH] well part of the custome svelte store works, the essential part at least --- .../src/TwoFactorAuthentication.svelte | 2 +- .../src/old_unused/loginStatusStore_old.js | 129 ++++++++++++++++++ .../api_front/src/stores/loginStatusStore.js | 105 +------------- 3 files changed, 136 insertions(+), 100 deletions(-) create mode 100644 srcs/requirements/svelte/api_front/src/old_unused/loginStatusStore_old.js diff --git a/srcs/requirements/svelte/api_front/src/TwoFactorAuthentication.svelte b/srcs/requirements/svelte/api_front/src/TwoFactorAuthentication.svelte index 8cdb9b45..2e4854ad 100644 --- a/srcs/requirements/svelte/api_front/src/TwoFactorAuthentication.svelte +++ b/srcs/requirements/svelte/api_front/src/TwoFactorAuthentication.svelte @@ -13,7 +13,7 @@ // testing loginStatus Custom Store const toggleTFA = () => { - loginStatus.toggleTFA; + loginStatus.toggleTFA(); console.log($loginStatus.tfa); } diff --git a/srcs/requirements/svelte/api_front/src/old_unused/loginStatusStore_old.js b/srcs/requirements/svelte/api_front/src/old_unused/loginStatusStore_old.js new file mode 100644 index 00000000..8070229c --- /dev/null +++ b/srcs/requirements/svelte/api_front/src/old_unused/loginStatusStore_old.js @@ -0,0 +1,129 @@ +import { writable } from "svelte/store"; + +// This is a "Custom Store" see that chapter in the Svelte Tutorial, should be fine +// NVM this is definitely overkill +// function createLogin() { +// const { subscribe, update } = writable(false); + +// return { +// subscribe, +// login: () => update(s => s = true), +// logout: () => update(s => s = false), +// } +// } +// export const loginStatus = createLogin(); + +// export const loginStatus = writable({ +// 42: false, +// tfa: false, +// }); + +// function createLoginStatus() { + +// //ok it really hated all this + +// // const store = writable({ +// // fortyTwo: false, +// // tfa: false, +// // }); + +// // return { +// // ...store, +// // subscribe, +// // // toggle42: () => update( l => l.fortyTwo = !l.fortyTwo ), +// // toggle42: () => store.update( fortyTwo => !fortyTwo ), +// // // toggleTFA: () => update( l => l.tfa = !l.tfa ), +// // toggleTFA: () => store.update( tfa => !tfa ), +// // isLogged: () => store.fortyTwo && store.tfa, +// // // isLogged: this.fortyTwo && this.tfa, +// // // it really doesn't like "this." +// // // isLogged: () => (this.tfa && this.fortyTwo), +// // // this. ? or (l) => l.tfa ... ? +// // } + + +// // doesn't seem to work... +// const { subscribe, update } = writable({ +// fortyTwo: false, +// tfa: false, +// }); + +// return { +// subscribe, +// // toggle42: () => update( l => l.fortyTwo = !l.fortyTwo ), +// toggle42: () => update( fortyTwo => !fortyTwo ), +// // toggleTFA: () => update( l => l.tfa = !l.tfa ), +// toggleTFA: () => update( tfa => !tfa ), +// // isLogged: () => fortyTwo && tfa, +// // isLogged: this.fortyTwo && this.tfa, +// // it really doesn't like "this." +// // isLogged: () => (this.tfa && this.fortyTwo), +// // this. ? or (l) => l.tfa ... ? +// isLogged() { +// return fortyTwo && tfa; +// }, +// } + +// // possible other way of doing this + +// // const store = writable({ +// // fortyTwo: false, +// // tfa: false, +// // }); + +// // return { +// // ...store, +// // subscribe, +// // // toggle42: () => update( l => l.fortyTwo = !l.fortyTwo ), +// // toggle42: () => store.update( l.fortyTwo => !l.fortyTwo ), +// // toggleTFA: () => store.update( l => l.tfa = !l.tfa ), +// // isLogged: store.fortyTwo && store.tfa, +// // // isLogged: () => (this.tfa && this.fortyTwo), +// // // this. ? or (l) => l.tfa ... ? +// // } + +// } + +function createLoginStatus() { + const { subscribe, update } = writable({ + fortyTwo: false, + tfa: false, + }); + + function toggle42() { + update( (old) => ({...old, fortyTwo: !old.fortyTwo}) ); + }; + + function toggleTFA() { + // update( () => { + // self.tfa = !self.tfa; + // return self; + // }) + // console.log("testing"); + update( (old) => ({...old, tfa: !old.tfa}) ); + }; + + function isLogged() { + // return (l) => {l.fortyTwo && l.tfa}; + // return self.fortyTwo && self.tfa; + // return fortyTwo && tfa; + }; + + return { subscribe, update, toggle42, toggleTFA, isLogged }; +} + +export const loginStatus = createLoginStatus(); + +// OK let's try a totally new approach + +// const _loginStatus = writable({ +// fortyTwo: false, +// tfa: false, +// }) + +// export const loginStatus = { +// subscribe: _loginStatus.subscribe, +// set: _loginStatus.set, +// update: _loginStatus.update, +// toggle42: () => +// } \ No newline at end of file diff --git a/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js b/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js index f74d3ed4..0c2c31d0 100644 --- a/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js +++ b/srcs/requirements/svelte/api_front/src/stores/loginStatusStore.js @@ -1,120 +1,27 @@ import { writable } from "svelte/store"; -// This is a "Custom Store" see that chapter in the Svelte Tutorial, should be fine -// NVM this is definitely overkill -// function createLogin() { -// const { subscribe, update } = writable(false); - -// return { -// subscribe, -// login: () => update(s => s = true), -// logout: () => update(s => s = false), -// } -// } -// export const loginStatus = createLogin(); - -// export const loginStatus = writable({ -// 42: false, -// tfa: false, -// }); - -// function createLoginStatus() { - -// //ok it really hated all this - -// // const store = writable({ -// // fortyTwo: false, -// // tfa: false, -// // }); - -// // return { -// // ...store, -// // subscribe, -// // // toggle42: () => update( l => l.fortyTwo = !l.fortyTwo ), -// // toggle42: () => store.update( fortyTwo => !fortyTwo ), -// // // toggleTFA: () => update( l => l.tfa = !l.tfa ), -// // toggleTFA: () => store.update( tfa => !tfa ), -// // isLogged: () => store.fortyTwo && store.tfa, -// // // isLogged: this.fortyTwo && this.tfa, -// // // it really doesn't like "this." -// // // isLogged: () => (this.tfa && this.fortyTwo), -// // // this. ? or (l) => l.tfa ... ? -// // } - - -// // doesn't seem to work... -// const { subscribe, update } = writable({ -// fortyTwo: false, -// tfa: false, -// }); - -// return { -// subscribe, -// // toggle42: () => update( l => l.fortyTwo = !l.fortyTwo ), -// toggle42: () => update( fortyTwo => !fortyTwo ), -// // toggleTFA: () => update( l => l.tfa = !l.tfa ), -// toggleTFA: () => update( tfa => !tfa ), -// // isLogged: () => fortyTwo && tfa, -// // isLogged: this.fortyTwo && this.tfa, -// // it really doesn't like "this." -// // isLogged: () => (this.tfa && this.fortyTwo), -// // this. ? or (l) => l.tfa ... ? -// isLogged() { -// return fortyTwo && tfa; -// }, -// } - -// // possible other way of doing this - -// // const store = writable({ -// // fortyTwo: false, -// // tfa: false, -// // }); - -// // return { -// // ...store, -// // subscribe, -// // // toggle42: () => update( l => l.fortyTwo = !l.fortyTwo ), -// // toggle42: () => store.update( l.fortyTwo => !l.fortyTwo ), -// // toggleTFA: () => store.update( l => l.tfa = !l.tfa ), -// // isLogged: store.fortyTwo && store.tfa, -// // // isLogged: () => (this.tfa && this.fortyTwo), -// // // this. ? or (l) => l.tfa ... ? -// // } - -// } - function createLoginStatus() { - // const store = writable({ - // fortyTwo: false, - // tfa: false, - // }); - const { subscribe, update } = writable({ fortyTwo: false, tfa: false, }); function toggle42() { - update( (l) => { - l.fortyTwo = !l.fortyTwo; - return l; - }) + update( (old) => ({...old, fortyTwo: !old.fortyTwo}) ); }; function toggleTFA() { - update( (l) => { - l.tfa = !l.tfa; - return l; - }) + update( (old) => ({...old, tfa: !old.tfa}) ); }; function isLogged() { // return (l) => {l.fortyTwo && l.tfa}; - return fortyTwo && tfa; + // return self.fortyTwo && self.tfa; + // return fortyTwo && tfa; + return (old) => (old.fortyTwo && old.tfa); }; return { subscribe, update, toggle42, toggleTFA, isLogged }; } -export const loginStatus = createLoginStatus(); \ No newline at end of file +export const loginStatus = createLoginStatus();