]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(plugins): allow chaining
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 29 Apr 2021 12:40:07 +0000 (14:40 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 29 Apr 2021 12:41:35 +0000 (14:41 +0200)
__tests__/storePlugins.spec.ts
src/rootStore.ts

index 13e5d248ae31df2464ae8e270858f9ef70d942cd..fde8ccf3eb853fcfb73895cf3fc9090c30df984b 100644 (file)
@@ -8,6 +8,8 @@ declare module '../src' {
     uid: App['_uid']
     hasApp: boolean
     idFromPlugin: Id
+    globalA: string
+    globalB: string
   }
 }
 
@@ -27,6 +29,7 @@ describe('store plugins', () => {
       },
     },
   })
+
   it('adds properties to stores', () => {
     const pinia = createPinia()
 
@@ -92,4 +95,17 @@ describe('store plugins', () => {
     const store = useStore(pinia)
     expect(store.doubleN).toBe(40)
   })
+
+  it('allows chaining', () => {
+    const pinia = createPinia()
+
+    // must call use after installing the plugin
+    pinia.use(() => ({ globalA: 'a' })).use(() => ({ globalB: 'b' }))
+
+    mount({ template: 'none' }, { global: { plugins: [pinia] } })
+
+    const store = useStore(pinia)
+    expect(store.globalA).toBe('a')
+    expect(store.globalB).toBe('b')
+  })
 })
index 8c115f707e1e16906e93af0eb9b7d91c8f13c8c2..dd4f1c22327c75f9825c6b2565d1502280223313 100644 (file)
@@ -119,7 +119,7 @@ export interface Pinia {
    *
    * @param plugin - store plugin to add
    */
-  use(plugin: PiniaStorePlugin): void
+  use(plugin: PiniaStorePlugin): Pinia
 
   /**
    * Installed store plugins
@@ -194,6 +194,7 @@ export function createPinia(): Pinia {
       } else {
         _p.push(plugin)
       }
+      return this
     },
 
     _p,