Browse Source

Don't bother setting values if they are already the same, as they can
trigger expensive refreshes.

Ian Rose 7 years ago
parent
commit
a0c90e090a
2 changed files with 9 additions and 1 deletions
  1. 5 0
      packages/codemirror/src/editor.ts
  2. 4 1
      packages/observables/src/modeldb.ts

+ 5 - 0
packages/codemirror/src/editor.ts

@@ -1175,6 +1175,11 @@ namespace Private {
    */
   export
   function setOption<K extends keyof CodeMirrorEditor.IConfig>(editor: CodeMirror.Editor, option: K, value: CodeMirrorEditor.IConfig[K]): void {
+    // Don't bother setting the option if it is already the same.
+    const oldValue = getOption(editor, option);
+    if (oldValue === value) {
+      return;
+    }
     switch (option) {
     case 'lineWrap':
       editor.setOption('lineWrapping', value);

+ 4 - 1
packages/observables/src/modeldb.ts

@@ -10,7 +10,7 @@ import {
 } from '@phosphor/signaling';
 
 import {
-  JSONValue, JSONObject
+  JSONExt, JSONValue, JSONObject
 } from '@phosphor/coreutils';
 
 import {
@@ -319,6 +319,9 @@ class ObservableValue implements IObservableValue {
    */
   set(value: JSONValue): void {
     let oldValue = this._value;
+    if (JSONExt.deepEqual(oldValue, value)) {
+      return;
+    }
     this._value = value;
     this._changed.emit({
       oldValue: oldValue,