Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #385 from ianwalter/next
Browse files Browse the repository at this point in the history
Updating merge to 9 alpha
  • Loading branch information
Ian Walter authored Jun 10, 2020
2 parents 7acf6f6 + d0fe6f4 commit a8be6ab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 44 deletions.
34 changes: 17 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Copyright 2019 Ian Walter
Copyright Ian Walter <pub@ianwalter.dev> (https://ianwalter.dev)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

* The above copyright notice and this permission notice shall be included in all
* The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

* The software may not be used by individuals, corporations, governments, or
other groups for systems or activities that actively and knowingly endanger,
harm, or otherwise threaten the physical, mental, economic, or general
* The software may not be used by individuals, corporations, governments, or
other groups for systems or activities that actively and knowingly endanger,
harm, or otherwise threaten the physical, mental, economic, or general
well-being of individuals or groups in violation of the United Nations
Universal Declaration of Human Rights
Universal Declaration of Human Rights
(https://www.un.org/en/universal-declaration-human-rights/).

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

This license is derived from the MIT License, as amended to limit the impact of
This license is derived from the MIT License, as amended to limit the impact of
the unethical use of open source software.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
"dependencies": {
"@ianwalter/clone": "^6.0.1",
"@ianwalter/merge": "^7.0.0"
"@ianwalter/merge": "^9.0.0-4"
},
"devDependencies": {
"@fullhuman/purgecss-loader": "^1.0.0",
Expand Down
50 changes: 28 additions & 22 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ const { test } = require('@ianwalter/bff')
const Vue = require('vue')
const Vuex = require('vuex')
const clone = require('@ianwalter/clone')
const merge = require('@ianwalter/merge')
const VuexReset = require('.')

Vue.use(Vuex)

test('state is reset when trigger mutation executed', ctx => {
const state = { message: 'Hello!' }
test('state is reset when trigger mutation executed', t => {
const state = { message: 'Hello!', with: { my: { e: 'yes', open: true } } }
const store = new Vuex.Store({
plugins: [VuexReset()],
state: clone(state),
mutations: {
message: (state, message) => (state.message = message),
data: (state, data) => merge(state, data),
reset: () => {}
}
})
store.commit('message', 'Greetings!')
store.commit('reset')
ctx.expect(store.state).toEqual(state)
t.expect(store.state).toEqual(state)
store.commit('message', 'Yo!')
store.commit('reset')
ctx.expect(store.state).toEqual(state)
t.expect(store.state).toEqual(state)
store.commit('data', { with: { my: { open: false } } })
t.expect(store.state.with).toEqual({ my: { e: 'yes', open: false } })
store.commit('reset')
t.expect(store.state).toEqual(state)
})

test('only module state is reset when module mutation executed', ctx => {
test('only module state is reset when module mutation executed', t => {
const rootMessage = 'Yo!'
const songName = 'One Touch'
const state = { message: 'Hello!' }
Expand Down Expand Up @@ -53,19 +59,19 @@ test('only module state is reset when module mutation executed', ctx => {
})
store.commit('message', rootMessage)
store.commit('sample/song/name', songName)
ctx.expect(store.state['sample/song'].name).toBe(songName)
t.expect(store.state['sample/song'].name).toBe(songName)
store.commit('sample/song/collection', 'Summer')
ctx.expect(store.state['sample/song'].collections).toEqual(['Summer'])
ctx.expect(store.state['sample/song'].map).toEqual({ Summer: 1 })
t.expect(store.state['sample/song'].collections).toEqual(['Summer'])
t.expect(store.state['sample/song'].map).toEqual({ Summer: 1 })
store.commit('sample/song/reset')
ctx.expect(store.state.message).toBe(rootMessage)
ctx.expect(store.state['sample/song']).toEqual(songState)
t.expect(store.state.message).toBe(rootMessage)
t.expect(store.state['sample/song']).toEqual(songState)
store.commit('sample/song/collection', 'Dance')
store.commit('reset')
ctx.expect(store.state['sample/song']).toEqual(songState)
t.expect(store.state['sample/song']).toEqual(songState)
})

test('module state can be reset when registered dynamically', ctx => {
test('module state can be reset when registered dynamically', t => {
const rootMessage = 'Yo!'
const songName = 'One Touch'
const state = { message: 'Hello!' }
Expand All @@ -90,15 +96,15 @@ test('module state can be reset when registered dynamically', ctx => {
store.registerModuleState('song', song)
store.commit('message', rootMessage)
store.commit('song/name', songName)
ctx.expect(store.state.song.name).toBe(songName)
t.expect(store.state.song.name).toBe(songName)
store.commit('song/collection', 'Summer')
ctx.expect(store.state.song.collections).toEqual(['Summer'])
t.expect(store.state.song.collections).toEqual(['Summer'])
store.commit('song/reset')
ctx.expect(store.state.message).toEqual(rootMessage)
ctx.expect(store.state.song).toEqual(songState)
t.expect(store.state.message).toEqual(rootMessage)
t.expect(store.state.song).toEqual(songState)
})

test('ssr state is used but can reset to initial state', ctx => {
test('ssr state is used but can reset to initial state', t => {
const message = 'Yo!'
const state = { message: 'Hello!', song: 'The Wheel' }
const store = new Vuex.Store({
Expand All @@ -108,12 +114,12 @@ test('ssr state is used but can reset to initial state', ctx => {
reset: () => true
}
})
ctx.expect(store.state.message).toBe(message)
t.expect(store.state.message).toBe(message)
store.commit('reset')
ctx.expect(store.state).toEqual(state)
t.expect(store.state).toEqual(state)
})

test('current route state is kept if it exists when reset', ctx => {
test('current route state is kept if it exists when reset', t => {
const state = { message: 'Hello!' }
const route = { path: '/' }
const path = '/welcome'
Expand All @@ -137,6 +143,6 @@ test('current route state is kept if it exists when reset', ctx => {
store.commit('route/path', path)
store.commit('message', 'Greetings!')
store.commit('reset')
ctx.expect(store.state.message).toBe(state.message)
ctx.expect(store.state.route.path).toBe(path)
t.expect(store.state.message).toBe(state.message)
t.expect(store.state.route.path).toBe(path)
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@
resolved "https://registry.yarnpkg.com/@ianwalter/merge/-/merge-6.0.0.tgz#7d7facccc86fb407571c78de00a0bd2adca395cb"
integrity sha512-Ohskh/vqQFgW2Abaxd3kPYz/uNqoUmCSjU8kB8SoRieQqIOyXit1pFKYW4HmcoRcDFbktpWmS1QpIBoF74DGBg==

"@ianwalter/merge@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@ianwalter/merge/-/merge-7.0.0.tgz#2fc97113eea21c1fd25132c8ddb93d3f20a83d04"
integrity sha512-PuJJiUQZSNRu6zrC6xrJx9/gX0NX9rilQ646+VBSj+X7RRBUWOogqxEUHojOJcwYTt2JzWVV9DIvvsZMkfZP5Q==
"@ianwalter/merge@^9.0.0-4":
version "9.0.0-4"
resolved "https://registry.yarnpkg.com/@ianwalter/merge/-/merge-9.0.0-4.tgz#eefb46c1ef866e7daa421237c3222fda5822ba1b"
integrity sha512-M0dxT2yn9WLbvDcdCqaeNzWuRgTv6pJmD2xHpxhvMRgA4jeP+/94lECGNTF1Fpchl80goc83qcyeUG5vLARmpw==

"@ianwalter/npm-short-name@^1.0.0":
version "1.0.0"
Expand Down

0 comments on commit a8be6ab

Please sign in to comment.