Fossil SCM

Simplified the previous commit considerably.

stephan 2020-05-15 19:25 fileedit-ajaxify
Commit 525bec99a33336a17ef369be409e7a2be280017a1d3b67b39a59e03b2306b399
1 file changed +11 -13
--- src/fossil.storage.js
+++ src/fossil.storage.js
@@ -30,10 +30,17 @@
3030
},
3131
removeItem: function(k){delete this.$[k]},
3232
clear: function(){this.$={}}
3333
});
3434
35
+ /**
36
+ For the dummy storage we need to differentiate between
37
+ $storage and its real property storage for hasOwnProperty()
38
+ to work properly...
39
+ */
40
+ const $storageHolder = $storage.hasOwnProperty('$') ? $storage.$ : $storage;
41
+
3542
/**
3643
A proxy for localStorage or sessionStorage or a
3744
page-instance-local proxy, if neither one is availble.
3845
3946
Which exact storage implementation is uses is unspecified, and
@@ -45,15 +52,11 @@
4552
set: (k,v)=>$storage.setItem(k,v),
4653
/** Sets storage key k to JSON.stringify(v). */
4754
setJSON: (k,v)=>$storage.setItem(k,JSON.stringify(v)),
4855
/** Returns the value for the given storage key, or
4956
dflt if the key is not found in the storage. */
50
- get: function(k,dflt){
51
- return (
52
- this.isTransient() ? $storage.$ : $storage
53
- ).hasOwnProperty(k) ? $storage.getItem(k) : dflt;
54
- },
57
+ get: (k,dflt)=>$storageHolder.hasOwnProperty(k) ? $storage.getItem(k) : dflt,
5558
/** Returns the JSON.parse()'d value of the given
5659
storage key's value, or dflt is the key is not
5760
found or JSON.parse() fails. */
5861
getJSON: function f(k,dflt){
5962
try {
@@ -62,30 +65,25 @@
6265
}
6366
catch(e){return dflt}
6467
},
6568
/** Returns true if the storage contains the given key,
6669
else false. */
67
- contains: function(k){
68
- return (
69
- this.isTransient() ? $storage.$ : $storage
70
- ).hasOwnProperty(k);
71
- },
70
+ contains: (k)=>$storageHolder.hasOwnProperty(k),
7271
/** Removes the given key from the storage. */
7372
remove: (k)=>$storage.removeItem(k),
7473
/** Clears ALL keys from the storage. */
7574
clear: ()=>$storage.clear(),
7675
/** Returns an array of all keys currently in the storage. */
77
- keys: ()=>Object.keys($storage),
76
+ keys: ()=>Object.keys($storageHolder),
7877
/** Returns true if this storage is transient (only available
7978
until the page is reloaded), indicating that fileStorage
8079
and sessionStorage are unavailable. */
81
- isTransient: ()=>!($storage===window.localStorage
82
- ||$storage===window.sessionStorage),
80
+ isTransient: ()=>$storageHolder!==$storage,
8381
/** Returns a symbolic name for the current storage mechanism. */
8482
storageImplName: function(){
8583
if($storage===window.localStorage) return 'localStorage';
8684
else if($storage===window.sessionStorage) return 'sessionStorage';
8785
else return 'transient';
8886
}
8987
};
9088
9189
})(window.fossil);
9290
--- src/fossil.storage.js
+++ src/fossil.storage.js
@@ -30,10 +30,17 @@
30 },
31 removeItem: function(k){delete this.$[k]},
32 clear: function(){this.$={}}
33 });
34
 
 
 
 
 
 
 
35 /**
36 A proxy for localStorage or sessionStorage or a
37 page-instance-local proxy, if neither one is availble.
38
39 Which exact storage implementation is uses is unspecified, and
@@ -45,15 +52,11 @@
45 set: (k,v)=>$storage.setItem(k,v),
46 /** Sets storage key k to JSON.stringify(v). */
47 setJSON: (k,v)=>$storage.setItem(k,JSON.stringify(v)),
48 /** Returns the value for the given storage key, or
49 dflt if the key is not found in the storage. */
50 get: function(k,dflt){
51 return (
52 this.isTransient() ? $storage.$ : $storage
53 ).hasOwnProperty(k) ? $storage.getItem(k) : dflt;
54 },
55 /** Returns the JSON.parse()'d value of the given
56 storage key's value, or dflt is the key is not
57 found or JSON.parse() fails. */
58 getJSON: function f(k,dflt){
59 try {
@@ -62,30 +65,25 @@
62 }
63 catch(e){return dflt}
64 },
65 /** Returns true if the storage contains the given key,
66 else false. */
67 contains: function(k){
68 return (
69 this.isTransient() ? $storage.$ : $storage
70 ).hasOwnProperty(k);
71 },
72 /** Removes the given key from the storage. */
73 remove: (k)=>$storage.removeItem(k),
74 /** Clears ALL keys from the storage. */
75 clear: ()=>$storage.clear(),
76 /** Returns an array of all keys currently in the storage. */
77 keys: ()=>Object.keys($storage),
78 /** Returns true if this storage is transient (only available
79 until the page is reloaded), indicating that fileStorage
80 and sessionStorage are unavailable. */
81 isTransient: ()=>!($storage===window.localStorage
82 ||$storage===window.sessionStorage),
83 /** Returns a symbolic name for the current storage mechanism. */
84 storageImplName: function(){
85 if($storage===window.localStorage) return 'localStorage';
86 else if($storage===window.sessionStorage) return 'sessionStorage';
87 else return 'transient';
88 }
89 };
90
91 })(window.fossil);
92
--- src/fossil.storage.js
+++ src/fossil.storage.js
@@ -30,10 +30,17 @@
30 },
31 removeItem: function(k){delete this.$[k]},
32 clear: function(){this.$={}}
33 });
34
35 /**
36 For the dummy storage we need to differentiate between
37 $storage and its real property storage for hasOwnProperty()
38 to work properly...
39 */
40 const $storageHolder = $storage.hasOwnProperty('$') ? $storage.$ : $storage;
41
42 /**
43 A proxy for localStorage or sessionStorage or a
44 page-instance-local proxy, if neither one is availble.
45
46 Which exact storage implementation is uses is unspecified, and
@@ -45,15 +52,11 @@
52 set: (k,v)=>$storage.setItem(k,v),
53 /** Sets storage key k to JSON.stringify(v). */
54 setJSON: (k,v)=>$storage.setItem(k,JSON.stringify(v)),
55 /** Returns the value for the given storage key, or
56 dflt if the key is not found in the storage. */
57 get: (k,dflt)=>$storageHolder.hasOwnProperty(k) ? $storage.getItem(k) : dflt,
 
 
 
 
58 /** Returns the JSON.parse()'d value of the given
59 storage key's value, or dflt is the key is not
60 found or JSON.parse() fails. */
61 getJSON: function f(k,dflt){
62 try {
@@ -62,30 +65,25 @@
65 }
66 catch(e){return dflt}
67 },
68 /** Returns true if the storage contains the given key,
69 else false. */
70 contains: (k)=>$storageHolder.hasOwnProperty(k),
 
 
 
 
71 /** Removes the given key from the storage. */
72 remove: (k)=>$storage.removeItem(k),
73 /** Clears ALL keys from the storage. */
74 clear: ()=>$storage.clear(),
75 /** Returns an array of all keys currently in the storage. */
76 keys: ()=>Object.keys($storageHolder),
77 /** Returns true if this storage is transient (only available
78 until the page is reloaded), indicating that fileStorage
79 and sessionStorage are unavailable. */
80 isTransient: ()=>$storageHolder!==$storage,
 
81 /** Returns a symbolic name for the current storage mechanism. */
82 storageImplName: function(){
83 if($storage===window.localStorage) return 'localStorage';
84 else if($storage===window.sessionStorage) return 'sessionStorage';
85 else return 'transient';
86 }
87 };
88
89 })(window.fossil);
90

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button