浏览代码

Clean up handling of statedb values

Steven Silvester 7 年之前
父节点
当前提交
b2f00df746

+ 2 - 2
packages/application/src/layoutrestorer.ts

@@ -8,7 +8,7 @@ import {
 } from '@phosphor/commands';
 
 import {
-  JSONObject, PromiseDelegate, Token
+  JSONObject, PromiseDelegate, ReadonlyJSONObject, Token
 } from '@phosphor/coreutils';
 
 import {
@@ -86,7 +86,7 @@ namespace ILayoutRestorer {
     /**
      * A function that returns the args needed to restore an instance.
      */
-    args: (widget: T) => JSONObject;
+    args: (widget: T) => ReadonlyJSONObject;
 
     /**
      * A function that returns a unique persistent name for this instance.

+ 2 - 2
packages/apputils/src/instancetracker.ts

@@ -14,7 +14,7 @@ import {
 } from '@phosphor/commands';
 
 import {
-  JSONObject
+  ReadonlyJSONObject
 } from '@phosphor/coreutils';
 
 import {
@@ -457,7 +457,7 @@ namespace InstanceTracker {
     /**
      * A function that returns the args needed to restore an instance.
      */
-    args: (widget: T) => JSONObject;
+    args: (widget: T) => ReadonlyJSONObject;
 
     /**
      * A function that returns a unique persistent name for this instance.

+ 5 - 5
packages/coreutils/src/statedb.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  JSONObject, Token
+  ReadonlyJSONObject, Token
 } from '@phosphor/coreutils';
 
 import {
@@ -32,7 +32,7 @@ interface IStateItem {
   /**
    * The data value for a state item.
    */
-  value: JSONObject;
+  value: ReadonlyJSONObject;
 }
 
 
@@ -40,7 +40,7 @@ interface IStateItem {
  * The description of a state database.
  */
 export
-interface IStateDB extends IDataConnector<JSONObject> {
+interface IStateDB extends IDataConnector<ReadonlyJSONObject> {
   /**
    * The maximum allowed length of the data after it has been serialized.
    */
@@ -137,7 +137,7 @@ class StateDB implements IStateDB {
    * The promise returned by this method may be rejected if an error occurs in
    * retrieving the data. Non-existence of an `id` will succeed with `null`.
    */
-  fetch(id: string): Promise<JSONObject | undefined> {
+  fetch(id: string): Promise<ReadonlyJSONObject | undefined> {
     const key = `${this.namespace}:${id}`;
     const value = window.localStorage.getItem(key);
     if (!value) {
@@ -217,7 +217,7 @@ class StateDB implements IStateDB {
    * requirement for `fetch()`, `remove()`, and `save()`, it *is* necessary for
    * using the `fetchNamespace()` method.
    */
-  save(id: string, value: JSONObject): Promise<void> {
+  save(id: string, value: ReadonlyJSONObject): Promise<void> {
     try {
       const key = `${this.namespace}:${id}`;
       const serialized = JSON.stringify(value);

+ 1 - 0
packages/faq-extension/package.json

@@ -15,6 +15,7 @@
   "dependencies": {
     "@jupyterlab/application": "^0.8.3",
     "@jupyterlab/apputils": "^0.8.2",
+    "@phosphor/coreutils": "^1.2.0",
     "@phosphor/messaging": "^1.2.1",
     "@phosphor/virtualdom": "^1.1.1"
   },

+ 5 - 1
packages/faq-extension/src/index.ts

@@ -9,6 +9,10 @@ import {
   ICommandPalette, InstanceTracker
 } from '@jupyterlab/apputils';
 
+import {
+  JSONExt
+} from '@phosphor/coreutils';
+
 import {
   FaqModel, FaqWidget
 } from './widget';
@@ -54,7 +58,7 @@ function activate(app: JupyterLab, palette: ICommandPalette, restorer: ILayoutRe
   // Handle state restoration.
   restorer.restore(tracker, {
     command,
-    args: () => {},
+    args: () => JSONExt.emptyObject,
     name: () => 'faq'
   });