Repository: Kong/swrv (ts)

Issue:
Get last known state of data if there is no `fn`
In the case, we want to share data between components.

For example, there is an app config needs to be got from network when app is starting.
```
// in component App
const { data: appConfig } = useSWRV('/app/config', configFetcher);
....
// in component B
const { data: appConfig } = useSWRV('/app/config');
```


Pull request:
fix(fetcher) allow optional fetcher to not revalidate
Fixes #48

Patch:
diff --git a/src/use-swrv.ts b/src/use-swrv.ts
index c872697..8a30833 100644
--- a/src/use-swrv.ts
+++ b/src/use-swrv.ts
@@ -101,7 +101,7 @@ type StateRef<Data, Error> = { data: Data, error: Error, isValidating: boolean,
 /**
  * Stale-While-Revalidate hook to handle fetching, caching, validation, and more...
  */
-export default function useSWRV<Data = any, Error = any> (key: IKey, fn: fetcherFn<Data>, config?: IConfig): IResponse<Data, Error> {
+export default function useSWRV<Data = any, Error = any> (key: IKey, fn?: fetcherFn<Data>, config?: IConfig): IResponse<Data, Error> {
   let unmounted = false
   let isHydrated = false
 
@@ -154,6 +154,7 @@ export default function useSWRV<Data = any, Error = any> (key: IKey, fn: fetcher
    */
   const revalidate = async () => {
     const keyVal = keyRef.value
+    if (!fn) return
     if (!isDocumentVisible()) { return }
     const cacheItem = config.cache.get(keyVal, ttl)
     let newData = cacheItem && cacheItem.data


Test patch:
diff --git a/tests/use-swrv.spec.tsx b/tests/use-swrv.spec.tsx
index 0969cb8..a94cee6 100644
--- a/tests/use-swrv.spec.tsx
+++ b/tests/use-swrv.spec.tsx
@@ -228,6 +228,34 @@ describe('useSWRV', () => {
 
     done()
   })
+
+  it('should return cache when no fetcher provided', async done => {
+    let invoked = 0
+    const vm = new Vue({
+      template: `<div>d:{{ data }} cache:{{ dataFromCache }}</div>`,
+      setup  () {
+        const fetcher = () => {
+          invoked += 1
+          return new Promise(res => setTimeout(() => res('SWR'), 200))
+        }
+        const { data } = useSWRV('cache-key-5', fetcher)
+        const { data: dataFromCache } = useSWRV('cache-key-5')
+
+        return { data, dataFromCache }
+      }
+    }).$mount()
+
+    expect(invoked).toBe(1)
+
+    expect(vm.$el.textContent).toBe('d: cache:')
+    expect(invoked).toBe(1)
+    timeout(200)
+    await tick(vm, 2)
+
+    expect(vm.$el.textContent).toBe('d:SWR cache:SWR')
+    expect(invoked).toBe(1) // empty fetcher is OK
+    done()
+  })
 })
 
 describe('useSWRV - loading', () => {