Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 8b8d67d

Browse files
authored
Adds electron-store for simple persistance. (#21)
1 parent d198992 commit 8b8d67d

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

docs/stack.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Allows our app to auto-update.
7272
7373
A few quality-of-life utilities for working in Electron.
7474

75+
> **electron-store**
76+
77+
Persist JSON to the file system.
78+
7579
## Bundler
7680

7781
> **fuse-box**

package-lock.json

Lines changed: 42 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"dependencies": {
4040
"electron-is-dev": "0.2.0",
4141
"electron-log": "2.2.7",
42+
"electron-store": "^1.2.0",
4243
"electron-updater": "2.7.1",
4344
"mobx": "3.2.1",
4445
"mobx-react": "4.2.2",

src/renderer/features/example-using-tabs/welcome-screen/welcome-screen.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { LongTab } from '../long-tab/long-tab'
44
import { DogTab } from '../dog-tab/dog-tab'
55
import { Flex } from 'rebass'
66
import { Header } from '../header/header'
7+
import * as Store from 'electron-store'
8+
9+
// a sample store
10+
const store = new Store()
711

812
interface WelcomeScreenState {
913
tab: SampleTabType
@@ -14,7 +18,17 @@ export class WelcomeScreen extends React.Component<{}, WelcomeScreenState> {
1418
tab: 'one'
1519
}
1620

21+
componentDidMount() {
22+
// grab the persisted tab if we have one
23+
const tab = store.get('tab') || 'one'
24+
this.setState({ tab })
25+
}
26+
1727
setTab = (tab: SampleTabType) => {
28+
// persist the store... pretty trivial example, but ya, it's that easy.
29+
// Probably not the best idea to hit disk everytime you change a tab, but
30+
// if you're gunning for a prototype, everything is fair game.
31+
store.set('tab', tab)
1832
this.setState({ tab })
1933
}
2034

0 commit comments

Comments
 (0)