import { PublisherManager } from "@supersoniks/concorde/core/utils/PublisherProxy"; export const ensurePublisherValue = ( publisherId: string, defaultValue: T, ): void => { const publisher = PublisherManager.get(publisherId); const currentValue = typeof publisher.get === "function" ? publisher.get() : undefined; const isUnset = currentValue === undefined || currentValue === null || (typeof currentValue === "object" && !Array.isArray(currentValue) && Object.keys(currentValue).length === 0); if (isUnset) { publisher.set(defaultValue as T); } }; export const initializeDecoratorsDemoData = () => { ensurePublisherValue("demoData", { title: "Initial Title", user: { name: "Initial User" }, count: 0, }); ensurePublisherValue("demoUser", { name: "Demo User", email: "demo@example.com", }); ensurePublisherValue("demoSettings", { theme: "light", language: "en", }); ensurePublisherValue("demoUserSettings", { theme: "light", language: "en", }); ensurePublisherValue("autoValue1", 10); ensurePublisherValue("autoValue2", 20); ensurePublisherValue("waitAncestorDemo", { message: "Context from ancestor", }); ensurePublisherValue("combinedData", { title: "Combined Title" }); ensurePublisherValue("combinedUser", { name: "Combined User" }); ensurePublisherValue("combinedSettings", { theme: "dark" }); ensurePublisherValue("reflectData", { title: "Initial Reflected Title", count: 0, }); ensurePublisherValue("publishDemo", { email: "", message: "", }); ensurePublisherValue("dynamicProfiles", { alpha: { info: { title: "Profil Alpha" } }, beta: { info: { title: "Profil Beta" } }, }); ensurePublisherValue("dynamicProfilesAlt", { alpha: { info: { title: "Profil Alpha (Alt)" } }, beta: { info: { title: "Profil Beta (Alt)" } }, }); ensurePublisherValue("demoUsers", [ { id: 1, firstName: "Alice", lastName: "Smith", email: "alice.smith@example.com", }, { id: 2, firstName: "Bob", lastName: "Johnson", email: "bob.johnson@example.com", }, { id: 3, firstName: "Carol", lastName: "Williams", email: "carol.williams@example.com", }, { id: 4, firstName: "David", lastName: "Brown", email: "david.brown@example.com", }, { id: 5, firstName: "Eve", lastName: "Jones", email: "eve.jones@example.com", }, { id: 6, firstName: "Frank", lastName: "Garcia", email: "frank.garcia@example.com", }, { id: 7, firstName: "Grace", lastName: "Miller", email: "grace.miller@example.com", }, { id: 8, firstName: "Henry", lastName: "Davis", email: "henry.davis@example.com", }, { id: 9, firstName: "Ivy", lastName: "Martinez", email: "ivy.martinez@example.com", }, { id: 10, firstName: "Jack", lastName: "Taylor", email: "jack.taylor@example.com", }, ]); ensurePublisherValue("demoUsersAlt", [ { id: 11, firstName: "Sophie", lastName: "Lindquist", email: "sophie.lindquist@example.com", }, { id: 12, firstName: "Mateo", lastName: "Ortega", email: "mateo.ortega@example.com", }, { id: 13, firstName: "Jin", lastName: "Park", email: "jin.park@example.com", }, { id: 14, firstName: "Fatima", lastName: "El-Sayed", email: "fatima.el-sayed@example.com", }, { id: 15, firstName: "Lars", lastName: "Johansson", email: "lars.johansson@example.com", }, { id: 16, firstName: "Amara", lastName: "Singh", email: "amara.singh@example.com", }, { id: 17, firstName: "Zuri", lastName: "Okafor", email: "zuri.okafor@example.com", }, { id: 18, firstName: "Luca", lastName: "Rossi", email: "luca.rossi@example.com", }, { id: 19, firstName: "Ava", lastName: "Murphy", email: "ava.murphy@example.com", }, { id: 20, firstName: "Noah", lastName: "Keller", email: "noah.keller@example.com", }, ]); ensurePublisherValue("demoUsersSettings", [ { theme: "light", language: "en" }, { theme: "dark", language: "fr" }, { theme: "auto", language: "es" }, { theme: "light", language: "en" }, { theme: "dark", language: "fr" }, { theme: "auto", language: "es" }, { theme: "light", language: "en" }, { theme: "dark", language: "fr" }, { theme: "auto", language: "es" }, { theme: "light", language: "en" }, ]); ensurePublisherValue("demoUsersAltSettings", [ { theme: "dark", language: "de" }, { theme: "light", language: "it" }, { theme: "auto", language: "ja" }, { theme: "dark", language: "pt" }, { theme: "light", language: "ru" }, { theme: "auto", language: "zh" }, { theme: "dark", language: "ar" }, { theme: "light", language: "sv" }, { theme: "auto", language: "nl" }, { theme: "dark", language: "pl" }, ]); }; initializeDecoratorsDemoData();