From 978682e1df064f9f89bd13c228463025748c7467 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 5 Jun 2018 15:58:39 +0530 Subject: [PATCH] getEditor (#33) * chore - Add rollup devDependency - Add tsconfig for cypress intellisense * getEditor: getValue can now return a Promise that resolves to the value --- cypress/tsconfig.json | 12 ++++++++++++ package.json | 1 + src/cellmanager.js | 34 +++++++++++++++++++++------------- yarn.lock | 15 +++++++++++++++ 4 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 cypress/tsconfig.json diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json new file mode 100644 index 0000000..0748a24 --- /dev/null +++ b/cypress/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "allowJs": true, + "baseUrl": "../node_modules", + "types": [ + "cypress" + ] + }, + "include": [ + "**/*.*" + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 63499ef..2b0d6ce 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "mocha": "3.3.0", "postcss-cssnext": "^3.1.0", "postcss-nested": "^3.0.0", + "rollup": "^0.59.4", "rollup-plugin-commonjs": "^8.3.0", "rollup-plugin-eslint": "^4.0.0", "rollup-plugin-json": "^2.3.0", diff --git a/src/cellmanager.js b/src/cellmanager.js index 8a06782..11d0ac0 100644 --- a/src/cellmanager.js +++ b/src/cellmanager.js @@ -497,21 +497,29 @@ export default class CellManager { const editor = this.currentCellEditor; if (editor) { - const value = editor.getValue(); - const done = editor.setValue(value, rowIndex, col); - const oldValue = this.getCell(colIndex, rowIndex).content; + let valuePromise = editor.getValue(); - // update cell immediately - this.updateCell(colIndex, rowIndex, value); - $cell.focus(); - - if (done && done.then) { - // revert to oldValue if promise fails - done.catch((e) => { - console.log(e); - this.updateCell(colIndex, rowIndex, oldValue); - }); + // convert to stubbed Promise + if (!valuePromise.then) { + valuePromise = Promise.resolve(valuePromise); } + + valuePromise.then((value) => { + const done = editor.setValue(value, rowIndex, col); + const oldValue = this.getCell(colIndex, rowIndex).content; + + // update cell immediately + this.updateCell(colIndex, rowIndex, value); + $cell.focus(); + + if (done && done.then) { + // revert to oldValue if promise fails + done.catch((e) => { + console.log(e); + this.updateCell(colIndex, rowIndex, oldValue); + }); + } + }); } } diff --git a/yarn.lock b/yarn.lock index 053572e..eecf5c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -41,6 +41,10 @@ version "4.0.8" resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.8.tgz#d27600e9ba2f371e08695d90a0fe0408d89c7be7" +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + "@types/jquery@*": version "3.3.2" resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.3.2.tgz#8700226bdde24b6f98e3a60126dbaab3b2a3ab41" @@ -61,6 +65,10 @@ version "2.2.44" resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.44.tgz#1d4a798e53f35212fd5ad4d04050620171cd5b5e" +"@types/node@*": + version "10.3.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.3.1.tgz#51092fbacaed768a122a293814474fbf6e5e8b6d" + "@types/sinon-chai@2.7.29": version "2.7.29" resolved "https://registry.yarnpkg.com/@types/sinon-chai/-/sinon-chai-2.7.29.tgz#4db01497e2dd1908b2bd30d1782f456353f5f723" @@ -3347,6 +3355,13 @@ rollup-pluginutils@^2.0.1: estree-walker "^0.3.0" micromatch "^2.3.11" +rollup@^0.59.4: + version "0.59.4" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.59.4.tgz#6f80f7017c22667ff1bf3e62adf8624a44cc44aa" + dependencies: + "@types/estree" "0.0.39" + "@types/node" "*" + run-async@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"