Skip to content

Instantly share code, notes, and snippets.

@ISNIT0
Created May 20, 2020 11:02
Show Gist options
  • Save ISNIT0/7e1f2648c17db88e94b3c96165b8a2a5 to your computer and use it in GitHub Desktop.
Save ISNIT0/7e1f2648c17db88e94b3c96165b8a2a5 to your computer and use it in GitHub Desktop.

Exception

Error: Unexpected case
    at create (/Users/user/Projects/joe-docs/node_modules/lib0/dist/error-55a9a8c8.cjs:14:21)
    at Object.unexpectedCase (/Users/user/Projects/joe-docs/node_modules/lib0/dist/error-55a9a8c8.cjs:31:9)
    at findIndexSS (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1659:15)
    at findIndexCleanStart (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1700:17)
    at getItemCleanStart (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1721:18)
    at /Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:2204:19
    at iterateStructs (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1786:5)
    at /Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:2196:11
    at Map.forEach (<anonymous>)
    at /Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:2184:28
Error: Unexpected case
    at create (/Users/user/Projects/joe-docs/node_modules/lib0/dist/error-55a9a8c8.cjs:14:21)
    at Object.unexpectedCase (/Users/user/Projects/joe-docs/node_modules/lib0/dist/error-55a9a8c8.cjs:31:9)
    at findIndexSS (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1659:15)
    at findIndexCleanStart (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1700:17)
    at getItemCleanStart (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1721:18)
    at /Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:2204:19
    at iterateStructs (/Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:1786:5)
    at /Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:2196:11
    at Map.forEach (<anonymous>)
    at /Users/user/Projects/joe-docs/node_modules/yjs/dist/yjs.cjs:2184:28

UndoStack

[
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": []
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          13
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          13
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          26
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          26
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          40
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          40
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          53
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          53
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          66
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          66
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          80
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          80
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          92
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  },
  {
    "ds": {
      "clients": {
        "__map": true,
        "entries": []
      }
    },
    "beforeState": {
      "__map": true,
      "entries": [
        [
          685919273,
          92
        ]
      ]
    },
    "afterState": {
      "__map": true,
      "entries": [
        [
          685919273,
          102
        ]
      ]
    },
    "meta": {
      "__map": true,
      "entries": []
    }
  }
]

Parse with:

function fancyParse(str) {
  return JSON.parse(str, (key, value) => {
    if (value && value.__map) {
      return new Map(value.entries);
    } else if (value && value.__set) {
      return new Set(value.entries);
    } else {
      return value;
    }
  });
}

Doc state:

[
  2,
  2,
  169,
  152,
  137,
  199,
  2,
  0,
  4,
  1,
  5,
  113,
  117,
  105,
  108,
  108,
  48,
  97,
  115,
  100,
  102,
  97,
  115,
  100,
  102,
  10,
  97,
  115,
  100,
  102,
  97,
  115,
  100,
  102,
  10,
  97,
  115,
  100,
  102,
  97,
  115,
  100,
  102,
  10,
  97,
  115,
  100,
  102,
  97,
  115,
  100,
  102,
  97,
  10,
  115,
  100,
  102,
  97,
  115,
  100,
  102,
  97,
  115,
  100,
  102,
  129,
  169,
  152,
  137,
  199,
  2,
  47,
  54,
  1,
  249,
  223,
  134,
  152,
  6,
  0,
  193,
  169,
  152,
  137,
  199,
  2,
  47,
  169,
  152,
  137,
  199,
  2,
  48,
  30,
  2,
  169,
  152,
  137,
  199,
  2,
  1,
  48,
  54,
  249,
  223,
  134,
  152,
  6,
  1,
  0,
  30
]

UndoCode

const undoManager = new Y.UndoManager(yText);
undoManager.undoStack = undoStack;
while (undoManager.undoStack.length) {
    undoManager.undo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment