@warkypublic/svelix 0.1.33 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,15 +107,28 @@ const createGlobalStateStore = () => {
107
107
  let isStorageInitialized = false;
108
108
  let initializationPromise = null;
109
109
  let operationLock = Promise.resolve();
110
+ let hasAutoValidated = false;
110
111
  const store = writable(undefined);
111
112
  const getState = () => get(store);
112
113
  const setState = (partial, replace = false) => {
114
+ const before = get(store);
113
115
  store.update((current) => {
114
116
  const nextPartial = typeof partial === "function" ? partial(current) : partial;
115
117
  return replace
116
118
  ? nextPartial
117
119
  : { ...current, ...nextPartial };
118
120
  });
121
+ const after = get(store);
122
+ const handlerJustRegistered = !hasAutoValidated &&
123
+ typeof after.onFetchSession === "function" &&
124
+ typeof before?.onFetchSession !== "function";
125
+ if (handlerJustRegistered) {
126
+ hasAutoValidated = true;
127
+ const session = after.session;
128
+ if (hasSessionCredentials(session) && !session.validated) {
129
+ waitForInitialization().then(() => withOperationLock(() => fetchDataInternal()));
130
+ }
131
+ }
119
132
  };
120
133
  const setGlobalState = (partial) => {
121
134
  setState((state) => {
@@ -152,8 +165,8 @@ const createGlobalStateStore = () => {
152
165
  }));
153
166
  try {
154
167
  const currentState = getState();
168
+ const hasFetchHandler = typeof currentState.onFetchSession === "function";
155
169
  const result = await currentState.onFetchSession?.(currentState);
156
- const hasExistingSession = hasSessionCredentials(currentState.session);
157
170
  const nextUser = { ...currentState.user, ...result?.user };
158
171
  const nextSession = {
159
172
  ...currentState.session,
@@ -162,6 +175,14 @@ const createGlobalStateStore = () => {
162
175
  connected: true,
163
176
  loading: false,
164
177
  };
178
+ if (!hasFetchHandler) {
179
+ setGlobalState((state) => ({
180
+ ...state,
181
+ session: { ...state.session, connected: true, loading: false },
182
+ }));
183
+ return;
184
+ }
185
+ const hasExistingSession = hasSessionCredentials(currentState.session);
165
186
  const serverConfirmsSession = result?.session?.loggedIn === true || Boolean(result?.session?.authToken);
166
187
  const serverConfirmsUser = Boolean(result?.user?.guid || result?.user?.username);
167
188
  const alreadyValidated = currentState.session.validated === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warkypublic/svelix",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Svelte 5 component library with Skeleton UI and Tailwind CSS",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {