UNPKG

@betarena/ad-engine

Version:
150 lines (130 loc) 5.21 kB
// ╭──────────────────────────────────────────────────────────────────────────────────╮ // │ 📌 High Order Component Overview │ // ┣──────────────────────────────────────────────────────────────────────────────────┫ // │ ➤ Internal Svelte Code Format :|: V.8.0 │ // │ ➤ Status :|: 🔒 LOCKED │ // │ ➤ Author(s) :|: @migbash │ // ┣──────────────────────────────────────────────────────────────────────────────────┫ // │ 📝 Description │ // ┣──────────────────────────────────────────────────────────────────────────────────┫ // │ > Client 'Svelte/Store' │ // │ > Main Betarena Ad-Engine Session ('Ephermal') Store │ // ╰──────────────────────────────────────────────────────────────────────────────────╯ /* eslint-disable max-len */ // #region ➤ 📦 Package Imports import { writable } from 'svelte/store'; import type { IAdEngineSessionDataProp, IAdEngineSessionStore } from '../types/session.js'; // #endregion ➤ 📦 Package Imports // #region ➤ 📌 VARIABLES const /** * @description * 📝 store object instance */ storeObject: IAdEngineSessionStore = { isDarkTheme: false, data: { translation: { language: 'en', // @ts-expect-error - 📝 translation object translations: {}, }, } } ; // #endregion ➤ 📌 VARIABLES // #region ➤ 🛠️ METHODS /** * @author * @migbash * @summary * 💠 STORE * @description * 📝 SvelteJs store declaration * @returns * 📤 SvelteJs store */ function createLocalStore ( ) { const // ╭───── // │ NOTE: |:| 📣 default 'svelte/store' exports. // ╰───── { subscribe, set, update } = writable ( storeObject ), /** * @description * 📣 Complementary 'store' added methods. */ methods = { // ╭──────────────────────────────────────────────────────────────────────────────────╮ // │ 📣 Main Logic │ // ╰──────────────────────────────────────────────────────────────────────────────────╯ /** * @author * @migbash * @summary * - 🔹 HELPER * - IMPORTANT * @description * 📣 Update **target** `list` data of target `properties` to update. * @param { [ IAdEngineSessionDataProp, any] [] } data * 💠 **[required]** data point to update. * @return { void } */ updateData: ( data: [IAdEngineSessionDataProp, any][] ): void => { // ╭───── // │ NOTE: |:| loop over each data property to update // ╰───── for (const iterator of data) { const /** * @description */ dataTarget = iterator[0], /** * @description */ // eslint-disable-next-line no-unused-vars dataPoint = iterator[1] ; if (dataTarget == 'darkTheme') storeObject.isDarkTheme = !storeObject.isDarkTheme; else if (dataTarget == 'setTranslation') storeObject.data.translation = dataPoint; ; } set ( storeObject ); return; }, } ; return { subscribe, set, update, ...methods }; } // #endregion ➤ 🛠️ METHODS export const storeSession = createLocalStore();