Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Thomaash/vuex-ltm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.15
Choose a base ref
...
head repository: Thomaash/vuex-ltm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: release
Choose a head ref
Loading
16 changes: 10 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ version: 2.1
executors:
node:
docker:
- image: circleci/node:12.22
- image: cimg/node:21.7.3
working_directory: ~/repo

jobs:
@@ -20,7 +20,7 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-{{ checksum "package-lock.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

@@ -29,7 +29,7 @@ jobs:
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
key: v1-dependencies-{{ checksum "package-lock.json" }}

- persist_to_workspace:
root: .
@@ -70,8 +70,12 @@ jobs:
- attach_workspace:
at: .

# Test Renovate updated package versions (i.e. latest)
- run: npm run test

# Test various older versions
- run: npm run test:versions

gh_pages:
executor: node

@@ -82,13 +86,13 @@ jobs:
- run:
name: Prepare Git
command: |
git config user.email "tom.vycital@gmail.com"
git config user.name "Tomáš Vyčítal"
git config user.email "$GIT_EMAIL"
git config user.name "$GIT_NAME"
- run:
name: Publish
command: |
npx gh-pages -d 'docs' -m 'docs: update' -t -r "https://Thomaash:$GH_TOKEN@github.com/Thomaash/vuex-ltm.git"
npx gh-pages --dist 'docs' --message 'docs: update' --dotfiles --repo "https://$GH_USERNAME:$GH_TOKEN@github.com/Thomaash/vuex-ltm.git"
release:
executor: node
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ module.exports = {
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
plugins: ['@typescript-eslint', 'prettier', 'mocha'],
rules: {
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit ""
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm test
npx lint-staged
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"{src,test}/*.{j,t}s": ["eslint --fix", "git add"]
"{src,test}/*.{j,t}s": ["eslint --fix"]
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.18.1
99 changes: 92 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,97 @@
# Vuex - Long Term Memory

[![CircleCI](https://circleci.com/gh/Thomaash/vuex-ltm.svg?style=svg)](https://circleci.com/gh/Thomaash/vuex-ltm)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Renovate](https://badges.renovateapi.com/github/Thomaash/vuex-ltm)](https://app.renovatebot.com/)
[![npm](https://img.shields.io/npm/v/vuex-ltm)](https://www.npmjs.com/package/vuex-ltm)
[![dependencies Status](https://david-dm.org/Thomaash/vuex-ltm/status.svg)](https://david-dm.org/Thomaash/vuex-ltm)
[![devDependencies Status](https://david-dm.org/Thomaash/vuex-ltm/dev-status.svg)](https://david-dm.org/Thomaash/vuex-ltm?type=dev)
[![peerDependencies Status](https://david-dm.org/Thomaash/vuex-ltm/peer-status.svg)](https://david-dm.org/Thomaash/vuex-ltm?type=peer)
Async modular persistence for Vuex store.

Documentation: https://thomaash.github.io/vuex-ltm/

## Simple example

```javascript
import Vue from "vue"
import Vuex from "vuex"
import {
LTM,
dummyFilter,
localStorageWrapper,
replace,
saveAll,
simplyExecute
} from "vuex-ltm"

const ltm = new LTM({
// Persist immediatelly (even multiple times per second).
execute: simplyExecute,
// Persist all mutations.
filter: dummyFilter,
// Replace the state in Vuex when loading.
merge: replace,
// Persist the whole state.
reduce: saveAll,
// Persist into the localStorage as the 'app-state' item.
storage: localStorageWrapper("app-state", localStorage)
})

Vue.use(Vuex)
const store = new Vuex.Store({
state: {},
plugins: [ltm.plugin]
})
```

## Better example

```javascript
import Vue from 'vue'
import Vuex from 'vuex'
import {
LTM,
chromeSyncStorage,
deepMerge,
executeWithDelay,
localStorage,
mutationFilter,
pickModules
} from 'vuex-ltm'

const ltm = new LTM({
// Persist 2 seconds after the last change (prevents bursts).
execute: executeWithDelay(2000),
// Persist only after select mutations.
filter: mutationFilter(['mutation-type-1', 'mutation-type-2']),
// Merge the persisted state with the defaults in Vuex.
merge: deepMerge,
// Persist only some modules.
reduce: pickModules(['sync']),
// Persist into the chrome.storage.sync if in extension or into localStorage otherwise (dev/demo).
storage: chrome && chrome.storage && chrome.storage.sync
? chromeSyncStorage('app-state')
: localStorage('app-state'),
})

Vue.use(Vuex)
const store = new Vuex.Store({
state: {},
modules: {
local: …,
sync:
},
plugins: [ltm.plugin]
})

// You can also wait for the persisted state to be loaded (preferably with some nice spinner or something).
// Otherwise you'll have the defaults in Vuex before the persisted state is loaded.
;(async () => {
await ltm.ready
new Vue({
store,
render: h => h(App)
}).$mount('#app')
})()
```

## License

This project is dual licensed under [Apache 2.0](./LICENSE-APACHE-2.0) and [ISC](./LICENSE-ISC). Pick whichever you like more.

Async modular persistence for Vuex store.

2 changes: 1 addition & 1 deletion docs-misc/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ version: 2.1
executors:
node:
docker:
- image: circleci/node:12.22
- image: circleci/node:17.2.0
resource_class: small
working_directory: ~/repo

Loading