@mulanjs/mulanjs 1.0.1-dev.20260220121828 → 1.0.1-dev.20260220131258

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.
@@ -225,5 +225,5 @@ export function muPulse() {
225
225
  * Powered by the Iron Fortress persistent primitive.
226
226
  */
227
227
  export function muVault(key, initial, options = {}) {
228
- return persistent(key, initial, options);
228
+ return persistent(key, initial, Object.assign(Object.assign({}, options), { onCleanup: (fn) => onMuDestroy(fn) }));
229
229
  }
@@ -44,18 +44,13 @@ export function muSurge(array, taskFn, onProgress) {
44
44
  let completedItems = 0;
45
45
  // Convert function to string if it isn't already
46
46
  const fnStr = typeof taskFn === 'function' ? taskFn.toString() : taskFn;
47
- const workerCode = `
48
- const taskFn = ${fnStr};
49
- self.onmessage = function(e) {
50
- const { chunk, startIndex } = e.data;
51
- try {
52
- const results = chunk.map(taskFn);
53
- self.postMessage({ results, startIndex });
54
- } catch (err) {
55
- self.postMessage({ error: err.message, startIndex });
56
- }
57
- };
58
- `;
47
+ const workerPart1 = `const taskFn = ${fnStr};`;
48
+ const workerPart2 = `self.onmessage = function(e) {`;
49
+ const workerPart3 = ` const { chunk, startIndex } = e.data;`;
50
+ const workerPart4 = ` try { const results = chunk.map(taskFn); self.postMessage({ results, startIndex }); }`;
51
+ const workerPart5 = ` catch (err) { self.postMessage({ error: err.message, startIndex }); }`;
52
+ const workerPart6 = `};`;
53
+ const workerCode = [workerPart1, workerPart2, workerPart3, workerPart4, workerPart5, workerPart6].join('\n');
59
54
  const blob = new Blob([workerCode], { type: 'application/javascript' });
60
55
  const workerUrl = URL.createObjectURL(blob);
61
56
  return new Promise((resolve) => {
@@ -47,16 +47,11 @@ export function persistent(key, initialValue, options = {}) {
47
47
  }
48
48
  };
49
49
  window.addEventListener('storage', sync);
50
- // Auto-cleanup if used inside a component
51
- try {
52
- const { onMuDestroy } = require('./hooks');
53
- onMuDestroy(() => {
50
+ // Explicit cleanup if provided by the environment (e.g. Mulan Hooks)
51
+ if (options.onCleanup) {
52
+ options.onCleanup(() => {
54
53
  window.removeEventListener('storage', sync);
55
54
  });
56
55
  }
57
- catch (e) {
58
- // muVault might be used outside component setup in some advanced cases,
59
- // fallback to manual or no-cleanup if so.
60
- }
61
56
  return state;
62
57
  }