Skip to content

Commit

Permalink
✨ Release v1
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed May 26, 2021
1 parent 89acdf1 commit d2d2da1
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 75 deletions.
12 changes: 6 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const helpers_1 = require("./helpers");
class PersistedState {
constructor(opts, store) {
const defaultOptions = {
key: 'vuex',
fileName: 'vuex',
storageKey: 'state',
paths: [],
filter: undefined,
Expand All @@ -20,7 +20,7 @@ class PersistedState {
};
if (!opts.storage) {
defaultOptions.storage = new electron_store_1.default({
name: defaultOptions.key
name: defaultOptions.fileName
});
}
this.opts = Object.assign({}, defaultOptions, opts);
Expand All @@ -44,12 +44,12 @@ class PersistedState {
}
}
loadInitialState() {
const state = this.getState();
if (!state)
const persistedState = this.getState();
if (!persistedState)
return;
if (this.opts.overwrite)
return this.store.replaceState(state);
const mergedState = deepmerge_1.default(this.store.state, state, {
return this.store.replaceState(persistedState);
const mergedState = deepmerge_1.default(this.store.state, persistedState, {
arrayMerge: this.opts.arrayMerger
});
this.store.replaceState(mergedState);
Expand Down
4 changes: 2 additions & 2 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Store from 'electron-store';
import { MutationPayload } from 'vuex';
export interface Options {
key?: string;
fileName?: string;
storageKey?: string;
paths?: string[];
filter?: (mutation: MutationPayload) => boolean;
Expand All @@ -12,7 +12,7 @@ export interface Options {
storage?: Store;
}
export interface FinalOptions {
key: string;
fileName: string;
storageKey: string;
paths: string[];
filter?: (mutation: MutationPayload) => boolean;
Expand Down
118 changes: 66 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vuex-electron-store",
"version": "0.1.0-beta",
"description": "",
"version": "0.1.0",
"description": "Persist and rehydrate your Vuex state in your Electron app.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
Expand Down Expand Up @@ -36,12 +36,12 @@
"devDependencies": {
"@betahuhn/config": "^1.1.0",
"@types/node": "^15.6.1",
"@typescript-eslint/eslint-plugin": "^4.24.0",
"@typescript-eslint/parser": "^4.24.0",
"eslint": "^7.26.0",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^7.27.0",
"ts-node": "^9.1.1",
"tsc-watch": "^4.2.9",
"typescript": "^4.2.4",
"tsc-watch": "^4.4.0",
"typescript": "^4.3.2",
"vue": "^2.6.12",
"vuex": "^3.6.2"
},
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PersistedState {

constructor(opts: Options, store: VuexStore<any>) {
const defaultOptions: any = {
key: 'vuex',
fileName: 'vuex',
storageKey: 'state',
paths: [],
filter: undefined,
Expand All @@ -24,7 +24,7 @@ class PersistedState {

if (!opts.storage) {
defaultOptions.storage = new Store({
name: defaultOptions.key
name: defaultOptions.fileName
})
}

Expand Down Expand Up @@ -53,12 +53,12 @@ class PersistedState {
}

loadInitialState(): void {
const state = this.getState()
if (!state) return
const persistedState = this.getState()
if (!persistedState) return

if (this.opts.overwrite) return this.store.replaceState(state)
if (this.opts.overwrite) return this.store.replaceState(persistedState)

const mergedState = merge(this.store.state, state, {
const mergedState = merge(this.store.state, persistedState, {
arrayMerge: this.opts.arrayMerger
})

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Store from 'electron-store'
import { MutationPayload } from 'vuex'

export interface Options {
key?: string;
fileName?: string;
storageKey?: string;
paths?: string[];
filter?: (mutation: MutationPayload) => boolean;
Expand All @@ -15,7 +15,7 @@ export interface Options {
}

export interface FinalOptions {
key: string;
fileName: string;
storageKey: string;
paths: string[];
filter?: (mutation: MutationPayload) => boolean;
Expand Down

0 comments on commit d2d2da1

Please sign in to comment.