@fireproof/core 0.7.2-dev.2 → 0.7.2-dev.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,11 +7,6 @@ const defaultConfig = {
7
7
  export class Browser extends Base {
8
8
  constructor(name, config = {}) {
9
9
  super(name, Object.assign({}, defaultConfig, config));
10
- this.isBrowser = false;
11
- try {
12
- this.isBrowser = window.localStorage && true;
13
- }
14
- catch (e) { }
15
10
  }
16
11
  withDB = async (dbWorkFun) => {
17
12
  if (!this.idb) {
@@ -48,12 +43,18 @@ export class Browser extends Base {
48
43
  });
49
44
  }
50
45
  loadHeader(branch = 'main') {
51
- return this.isBrowser && localStorage.getItem(this.headerKey(branch));
46
+ try {
47
+ return JSON.parse(localStorage.getItem(this.headerKey(branch)));
48
+ }
49
+ catch (e) { }
52
50
  }
53
51
  async writeHeader(branch, header) {
54
52
  if (this.config.readonly)
55
53
  return;
56
- return this.isBrowser && localStorage.setItem(this.headerKey(branch), this.prepareHeader(header));
54
+ try {
55
+ return localStorage.setItem(this.headerKey(branch), this.prepareHeader(header));
56
+ }
57
+ catch (e) { }
57
58
  }
58
59
  headerKey(branch = 'main') {
59
60
  return this.config.headerKeyPrefix + this.name + '.' + branch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core",
3
- "version": "0.7.2-dev.2",
3
+ "version": "0.7.2-dev.4",
4
4
  "description": "Live data for React, accelerated by proofs, powered by IPFS",
5
5
  "main": "dist/src/fireproof.js",
6
6
  "module": "dist/src/fireproof.mjs",
package/src/database.js CHANGED
@@ -86,6 +86,7 @@ export class Database {
86
86
  * @instance
87
87
  */
88
88
  toJSON () {
89
+ // todo this prepareHeader ignores secondary storage, need both
89
90
  return this.blocks.valet ? this.blocks.valet.primary.prepareHeader(this.toHeader(), false) : this.toHeader() // omg
90
91
  }
91
92
 
@@ -10,10 +10,6 @@ const defaultConfig = {
10
10
  export class Browser extends Base {
11
11
  constructor (name, config = {}) {
12
12
  super(name, Object.assign({}, defaultConfig, config))
13
- this.isBrowser = false
14
- try {
15
- this.isBrowser = window.localStorage && true
16
- } catch (e) {}
17
13
  }
18
14
 
19
15
  withDB = async dbWorkFun => {
@@ -53,12 +49,16 @@ export class Browser extends Base {
53
49
  }
54
50
 
55
51
  loadHeader (branch = 'main') {
56
- return this.isBrowser && localStorage.getItem(this.headerKey(branch))
52
+ try {
53
+ return JSON.parse(localStorage.getItem(this.headerKey(branch)))
54
+ } catch (e) {}
57
55
  }
58
56
 
59
57
  async writeHeader (branch, header) {
60
58
  if (this.config.readonly) return
61
- return this.isBrowser && localStorage.setItem(this.headerKey(branch), this.prepareHeader(header))
59
+ try {
60
+ return localStorage.setItem(this.headerKey(branch), this.prepareHeader(header))
61
+ } catch (e) {}
62
62
  }
63
63
 
64
64
  headerKey (branch = 'main') {