Skip to content

Commit

Permalink
feat: add nuxtJS and SSR support (#109)
Browse files Browse the repository at this point in the history
* feat: add nuxtJS and SSR support

* fix tests

* more SSR support

* changelog
  • Loading branch information
pikax committed Jan 30, 2020
1 parent ebd89e5 commit 4d73885
Show file tree
Hide file tree
Showing 46 changed files with 289 additions and 221 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [BroadcastChannel](https://pikax.me/vue-composable/composable/web/broadcastChannel) - reactive `BroadcastChannel API`
- [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef.md) - cross-tab reactive `ref`
- [Geolocation API](https://pikax.me/vue-composable/composable/web/geolocation)
- NuxtJS SSR support

### Changed

Expand Down
6 changes: 4 additions & 2 deletions docs/.vuepress/components/OnResizeExample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

<script>
import { reactive, ref } from "@vue/composition-api";
import { useOnResize } from "vue-composable";
import { useOnResize, isClient } from "vue-composable";
export default {
name: "on-resize-example",
setup(_) {
const { height, width, remove } = useOnResize(document.body);
const { height, width, remove } = useOnResize(
(isClient && document.body) || null
);
return {
height,
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ export default {

### Pagination example

<ClientOnly>

<array-pagination-example/>
</ClientOnly>

4 changes: 2 additions & 2 deletions docs/composable/_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ const { remove } = useOnScroll();

## Example

<ClientOnly>

<on-scroll-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/event/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const { remove } = useEvent(element, name, listener);

## Example

<ClientOnly>

<event-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/event/onMouseMove.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const { remove } = useOnMouseMove();

## Example

<ClientOnly>

<on-mouse-move-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/event/onResize.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const { remove } = useOnResize();

## Example

<ClientOnly>

<on-resize-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/event/onScroll.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const { remove } = useOnScroll();

## Example

<ClientOnly>

<on-scroll-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/external/axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ const { exec, cancel } = useAxios();
## Example
<ClientOnly>
<axios-example/>
</ClientOnly>
### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/misc/breakpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const { remove } = useBreakpoint();

## Example

<ClientOnly>

<breakpoint-example/>
</ClientOnly>


### Code

Expand Down
9 changes: 5 additions & 4 deletions docs/composable/misc/matchMedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ The `useMatchMedia` function exposes the following reactive state:
```js
import { useMatchMedia } from "vue-composable";

const { scrollTop, matches } = useMatchMedia();
const { supported, mediaQueryList, matches } = useMatchMedia();
```

| State | Type | Description |
| -------------- | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| supported | `Boolean` | Is MatchMedia supported |
| mediaQueryList | [MediaQueryList](https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList) | List of objects stores information on a media query |
| matches | `Boolean` | A Boolean that returns true if the document currently matches the media query list, or false if not. |
| matches | `Ref<Boolean>` | A Boolean that returns true if the document currently matches the media query list, or false if not. |

## Methods

Expand All @@ -45,9 +46,9 @@ const { remove } = useMatchMedia();

## Example

<ClientOnly>

<match-media-example/>
</ClientOnly>


### Code

Expand Down
12 changes: 6 additions & 6 deletions docs/composable/misc/sharedRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ If the master instance gets destroyed (the component unmounted or tab closed) a
## Example
<ClientOnly>
<shared-ref-video/>
</ClientOnly>
<ClientOnly>
<shared-ref-example/>
</ClientOnly>
### Code
Expand Down Expand Up @@ -200,9 +200,9 @@ const myShared = useSharedRef();
### Example
<ClientOnly>
<ref-shared-example/>
</ClientOnly>
#### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/pagination/arrayPagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const { next, prev, first, last } = useArrayPagination();

## Example

<ClientOnly>

<array-pagination-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/pagination/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const { next, prev, first, last } = usePagination();

## Example

<ClientOnly>

<pagination-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/promise/cancellablePromise.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const { exec, cancel } = useCancellablePromise();
## Example
<ClientOnly>
<cancellable-promise-example/>
</ClientOnly>
### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/promise/promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const { exec } = usePromise();
## Example
<ClientOnly>
<promise-example/>
</ClientOnly>
### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/promise/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const { cancel, exec } = useRetry();

## Example

<ClientOnly>

<retry-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/storage/localStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const { remove, clear, setSync } = useLocalStorage(key);
![Local Storage Cross tab](/vue-composable/localStorage.gif)
<ClientOnly>
<local-storage-example/>
</ClientOnly>
### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/storage/sessionStorage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const { remove, clear, setSync } = useSessionStorage(key);
## Example
<ClientOnly>
<Session-storage-example/>
</ClientOnly>
### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/storage/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This is recommended if you want to support safari users using private mode.

## Example

<ClientOnly>

<storage-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/broadcastChannel.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const { send, close, addListener } = useBroadcastChannel();
## Example
<ClientOnly>
<broadcast-channel-example/>
</ClientOnly>
### Code
Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const { exec } = useFetch();

## Example

<ClientOnly>

<fetch-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/geolocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const { refresh } = useGeolocation();
## Example
<ClientOnly>
<geolocation-example/>
</ClientOnly>
### Code
Expand Down
15 changes: 8 additions & 7 deletions docs/composable/web/intersectionObserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ The `useIntersectionObserver` function exposes the following reactive state:
```js
import { useIntersectionObserver } from "vue-composable";

const { elements, isIntersecting } = useIntersectionObserver(options);
const { supported, elements, isIntersecting } = useIntersectionObserver(
options
);
```

| State | Type | Description |
| -------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------- |
| elements | `IntersectionObserverEntry[]` | [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) |
| isIntersecting | `Boolean` | Returns true if **all** observed elements are intersection |
| State | Type | Description |
| -------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------- |
| supported | `Boolean` | Is supported |
| elements | `Ref<IntersectionObserverEntry[]>` | [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) |
| isIntersecting | `Ref<Boolean?` | Returns true if **all** observed elements are intersection |

## Methods

Expand All @@ -37,9 +40,7 @@ const { observe, unobserve, disconnect, debug } = useIntersectionObserver();

## Example

<ClientOnly>
<intersection-observer-example/>
</ClientOnly>

### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ The `useLanguage` function exposes the following methods:

## Example

<ClientOnly>

<language-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/networkInformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const { remove } = useNetworkInformation();

## Example

<ClientOnly>

<network-information-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/online.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const { supported, online } = useOnline();

## Example

<ClientOnly>

<online-example/>
</ClientOnly>


### Code

Expand Down
4 changes: 2 additions & 2 deletions docs/composable/web/pageVisibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const { visibility, hidden } = usePageVisibility();

## Example

<ClientOnly>

<page-visibility-example/>
</ClientOnly>


### Code

Expand Down

0 comments on commit 4d73885

Please sign in to comment.