vue#effectScope TypeScript Examples

The following examples show how to use vue#effectScope. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: i18n.ts    From vue-i18n-next with MIT License 6 votes vote down vote up
function createGlobal(
  options: I18nOptions,
  legacyMode: boolean,
  VueI18nLegacy: any // eslint-disable-line @typescript-eslint/no-explicit-any
): [EffectScope, VueI18n | Composer] {
  const scope = effectScope()
  if (!__BRIDGE__) {
    const obj =
      !__LITE__ && __FEATURE_LEGACY_API__ && legacyMode
        ? scope.run(() => createVueI18n(options, VueI18nLegacy))
        : scope.run(() => createComposer(options, VueI18nLegacy))
    if (obj == null) {
      throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR)
    }
    return [scope, obj]
  } else {
    if (!isLegacyVueI18n(VueI18nLegacy)) {
      throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N)
    }
    const obj = scope.run(() => createComposer(options, VueI18nLegacy))
    if (obj == null) {
      throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR)
    }
    return [scope, obj]
  }
}
Example #2
Source File: i18n.ts    From vue-i18n-next with MIT License 6 votes vote down vote up
function createGlobal(
  options: I18nOptions,
  legacyMode: boolean,
  VueI18nLegacy: any // eslint-disable-line @typescript-eslint/no-explicit-any
): [EffectScope, VueI18n | Composer] {
  const scope = effectScope()
  if (!__BRIDGE__) {
    const obj =
      !__LITE__ && __FEATURE_LEGACY_API__ && legacyMode
        ? scope.run(() => createVueI18n(options, VueI18nLegacy))
        : scope.run(() => createComposer(options, VueI18nLegacy))
    if (obj == null) {
      throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR)
    }
    return [scope, obj]
  } else {
    if (!isLegacyVueI18n(VueI18nLegacy)) {
      throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N)
    }
    const obj = scope.run(() => createComposer(options, VueI18nLegacy))
    if (obj == null) {
      throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR)
    }
    return [scope, obj]
  }
}