Skip to content

Commit

Permalink
minor polishments
Browse files Browse the repository at this point in the history
  • Loading branch information
filrak committed Jan 7, 2021
1 parent d8bd197 commit 34aef79
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
4 changes: 1 addition & 3 deletions packages/core/docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ module.exports = {
collapsable: false,
children: [
['/general/architecture', 'Architecture'],
['/general/i18n', 'i18n'],
['/general/error-handling', 'Error Handling'],
['/general/logging', 'Logging'],
['/general/performance', 'Performance'],
Expand All @@ -150,8 +149,7 @@ module.exports = {
collapsable: false,
children: [
['/guide/theme', 'Theme'],
['/guide/internationalization', 'Internationalization'],

['/guide/internationalization', 'Internationalization']
]
},
{
Expand Down
44 changes: 22 additions & 22 deletions packages/core/docs/general/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ A flexible way of error handling is essential for a framework like Vue Storefron

Each composable returns `error` - computed property. It is an object which has names of async functions from composable as keys and Error instance or null as a value.

Example usage:
```vue
<template>
<button @click="addToCart(product)">Add to cart</button>
Expand Down Expand Up @@ -37,29 +36,10 @@ export interface UseCartErrors {
}
```

## How to listen for errors?
Let's imagine you have some global components for error notifications. You want to send information about each new error to this component. But how to know when new error appears? You can observe error object with a simple watcher!

```ts
const { cart, error } = useCart()

watch(error, (error, prevError) => {
if (error.value.addItem && error.value.addItem !== prevError.value.addItem) sendInAppNotification('error', error.value.addItem.message)
if (error.value.removeItem && error.value.removeItem !== prevError.value.removeItem) sendInAppNotification('error', error.value.removeItem.message)
})
```

## Where can I find interface of the error property from a certain composable?
When you are writing a code inside a script part of the Vue's component, your IDE should give you hints dedicated for each type of composable. That's why you probably do not need to check these interfaces in the core's code.

However, if somewhy you still want to do that, you could find them inside [`packages/core/core/src/types.ts`](https://github.com/vuestorefront/vue-storefront/blob/next/packages/core/core/src/types.ts). Just search for `UseCartErrors` with your IDE inside.

Feel free to replace `UseCartErrors` with other composable name - `UseFacetErrors`, `UseWishlistErrors`, `UseProductErrors` etc.
:::details Where does the error come from?

## Where does error come from?
To better understand this part you should know what are factories of composables in our core.

Inside each factory's async method we are clearing the current error before integration's method call and setting it in catch block.
Inside each async method we are clearing the current error before integration's method call and setting it in catch block.
```ts
const addItem = async ({ product, quantity, customQuery }) => {
Logger.debug('useCart.addItem', { product, quantity });
Expand All @@ -85,3 +65,23 @@ const addItem = async ({ product, quantity, customQuery }) => {
}
};
```
:::

:::details Where can I find interface of the error property from a certain composable?

When you are writing a code inside a script part of the Vue's component, your IDE should give you hints dedicated for each type of composable. That's why you probably do not need to check these interfaces in the core's code.

However, if somewhy you still want to do that, you could find them inside [`packages/core/core/src/types.ts`](https://github.com/vuestorefront/vue-storefront/blob/next/packages/core/core/src/types.ts).

:::
## How to listen for errors?
Let's imagine you have some global components for error notifications. You want to send information about each new error to this component. But how to know when new error appears? You can observe error object with a simple watcher!

```ts
const { cart, error } = useCart()

watch(error, (error, prevError) => {
if (error.value.addItem && error.value.addItem !== prevError.value.addItem) sendInAppNotification('error', error.value.addItem.message)
if (error.value.removeItem && error.value.removeItem !== prevError.value.removeItem) sendInAppNotification('error', error.value.removeItem.message)
})
```
19 changes: 16 additions & 3 deletions packages/core/docs/guide/internationalization.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# Internationalization

By default we are using [`nuxt-i18n`](https://i18n.nuxtjs.org/) module for handling internationalization, but it's not mandatory to use it even if you are using Nuxt.
If you're building a shop for an international brand you want it being translated to different languages and using different currencies. In this doc you will learn how we're approaching i18n (internationalization) in Vue Storefront.

In order to provide a unified way of configuring i18n across the application for different modules and integrations, we have introduced the field `i18n` in each module's configuration that has the same format as `nuxt-i18n` options. Clearly, it's possible to add there any configuration if there is a necessity and it will be propagated to all other Vue Storefront modules.
::: tip i18n is not multi-tenancy!
This document explains only how to make a single shop instance available for multiple countries. If you need to build a system for multiple tenants we suggest creating an instance of Vue Storefront for each tenant and sharing common resources through an NPM package.
:::

By default, all Vue Storefront modules have `useNuxtI18nModule` property set to `true`. It means that they will use the same configuration as you provided for `nuxt-i18n` in `i18n` field of your `nuxt.config.js`
## Default setup
By default we are using [`nuxt-i18n`](https://i18n.nuxtjs.org/) module for handling both translations and currencies.

In the theme `nuxt-i18n` is using `$t('key')` to translate strings and `$n(number)` to add the currency sign. You can find the translation keys in `lang` directory of your project.

::: tip
Even though the module is included into the default theme it's not mandatory for your app to work and [you can always get rid of it.](#custom-configuration).
:::

In order to provide a unified way of configuring i18n across the application for different modules and integrations, we have introduced the field `i18n` in each module's configuration that has the same format as `nuxt-i18n` options. Add there any configuration if there is a necessity and it will be propagated to all other Vue Storefront modules.

All Vue Storefront integrations have `useNuxtI18nModule` property set to `true`. It means that they will use the same configuration as you provided for `nuxt-i18n` in `i18n` field of your `nuxt.config.js`

```js
// nuxt.config.js
Expand Down

0 comments on commit 34aef79

Please sign in to comment.