All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.lib.composables.toggleScope.mjs.map Maven / Gradle / Ivy

{"version":3,"file":"toggleScope.mjs","names":["effectScope","onScopeDispose","watch","useToggleScope","source","fn","scope","start","run","length","stop","active","undefined","immediate"],"sources":["../../src/composables/toggleScope.ts"],"sourcesContent":["// Utilities\nimport { effectScope, onScopeDispose, watch } from 'vue'\n\n// Types\nimport type { EffectScope, WatchSource } from 'vue'\n\nexport function useToggleScope (source: WatchSource, fn: (reset: () => void) => void) {\n  let scope: EffectScope | undefined\n  function start () {\n    scope = effectScope()\n    scope.run(() => fn.length\n      ? fn(() => { scope?.stop(); start() })\n      : (fn as any)()\n    )\n  }\n\n  watch(source, active => {\n    if (active && !scope) {\n      start()\n    } else if (!active) {\n      scope?.stop()\n      scope = undefined\n    }\n  }, { immediate: true })\n\n  onScopeDispose(() => {\n    scope?.stop()\n  })\n}\n"],"mappings":"AAAA;AACA,SAASA,WAAW,EAAEC,cAAc,EAAEC,KAAK,QAAQ,KAAK;;AAExD;;AAGA,OAAO,SAASC,cAAcA,CAAEC,MAA4B,EAAEC,EAA+B,EAAE;EAC7F,IAAIC,KAA8B;EAClC,SAASC,KAAKA,CAAA,EAAI;IAChBD,KAAK,GAAGN,WAAW,CAAC,CAAC;IACrBM,KAAK,CAACE,GAAG,CAAC,MAAMH,EAAE,CAACI,MAAM,GACrBJ,EAAE,CAAC,MAAM;MAAEC,KAAK,EAAEI,IAAI,CAAC,CAAC;MAAEH,KAAK,CAAC,CAAC;IAAC,CAAC,CAAC,GACnCF,EAAE,CAAS,CAChB,CAAC;EACH;EAEAH,KAAK,CAACE,MAAM,EAAEO,MAAM,IAAI;IACtB,IAAIA,MAAM,IAAI,CAACL,KAAK,EAAE;MACpBC,KAAK,CAAC,CAAC;IACT,CAAC,MAAM,IAAI,CAACI,MAAM,EAAE;MAClBL,KAAK,EAAEI,IAAI,CAAC,CAAC;MACbJ,KAAK,GAAGM,SAAS;IACnB;EACF,CAAC,EAAE;IAAEC,SAAS,EAAE;EAAK,CAAC,CAAC;EAEvBZ,cAAc,CAAC,MAAM;IACnBK,KAAK,EAAEI,IAAI,CAAC,CAAC;EACf,CAAC,CAAC;AACJ","ignoreList":[]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy