Browse Source

fix(reset): allow resetting null stores

Ryan Chandler 4 years ago
parent
commit
d707007c27

File diff suppressed because it is too large
+ 0 - 0
dist/spruce.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.module.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.module.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.umd.js


File diff suppressed because it is too large
+ 0 - 0
dist/spruce.umd.js.map


+ 1 - 1
src/index.js

@@ -114,7 +114,7 @@ const Spruce = {
     },
 
     reset(name, state) {
-        if (! this.stores[name]) {
+        if (this.stores[name] === undefined) {
             return;
         }
         

+ 9 - 2
tests/cypress/fixtures/reset/index.html

@@ -4,14 +4,21 @@
     </head>
     <body>
         <div x-data>
-            <span x-text="$store.foo.bar"></span>
-            <button x-on:click="Spruce.reset('foo', { bar: 'boo' })"></button>
+            <span data-basic x-text="$store.foo.bar"></span>
+            <button data-basic-update x-on:click="Spruce.reset('foo', { bar: 'boo' })"></button>
+        </div>
+
+        <div x-data>
+            <span data-null-store x-text="$store.example?.name"></span>
+            <button data-null-store-update x-on:click="Spruce.reset('example', { name: 'Ryan' })"></button>
         </div>
 
         <script src="/dist/spruce.umd.js"></script>
 
         <script>
             Spruce.store('foo', { bar: 'car' })
+
+            Spruce.store('example', null)
         </script>
     </body>
 </html>

+ 9 - 3
tests/cypress/integration/reset.spec.js

@@ -4,10 +4,16 @@ describe('reset', () => {
     it('should re-render after state reset', () => {
         cy.visit('/tests/cypress/fixtures/reset')
 
-        cy.get('span').should('have.text', 'car')
+        cy.get('span[data-basic]').should('have.text', 'car')
 
-        cy.get('button').click()
+        cy.get('button[data-basic-update]').click()
 
-        cy.get('span').should('have.text', 'boo')
+        cy.get('span[data-basic]').should('have.text', 'boo')
+
+        cy.get('[data-null-store]').should('have.text', '')
+
+        cy.get('[data-null-store-update]').click()
+
+        cy.get('[data-null-store]').should('have.text', 'Ryan')
     })
 })

Some files were not shown because too many files changed in this diff