code_before
stringlengths
16
1.81M
edits
stringlengths
4
328k
next_edit
stringlengths
0
76.5k
code_after
stringlengths
3
49.9M
label_window
sequencelengths
4
1.81k
instruction
stringlengths
20
51.9k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
each: { lines: COVERAGE_PERCENT, statements: COVERAGE_PERCENT, }, }, includeAllSources: true, phantomjsLauncher: { exitOnResourceError: true, },
</s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageOverrides: { "src/cell/cell*": { lines: 70, }, "src/common/clipboard*": { lines: 60, statements: 60, }, "src/headers/headerCell*": { lines: 70, statements: 70, }, }, }); </s> remove use: "istanbul-instrumenter-loader", </s> add loader: "istanbul-instrumenter-loader", options: { esModules: true, }, </s> remove /* istanbul ignore next */ </s> add </s> remove "module": "commonjs", </s> add "module": "es2015", </s> remove /* istanbul ignore next */ </s> add
excludes: coverageExcludes, overrides: coverageOverrides,
each: { lines: COVERAGE_PERCENT, statements: COVERAGE_PERCENT, excludes: coverageExcludes, overrides: coverageOverrides, }, }, includeAllSources: true, phantomjsLauncher: { exitOnResourceError: true, },
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/karma-build-scripts/createKarmaConfig.js
}, { enforce: "post", test: /src\/.*\.tsx?$/, use: "istanbul-instrumenter-loader", }, { test: /\.(eot|ttf|woff|woff2|svg|png)$/, loader: require.resolve("file-loader"), },
</s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageOverrides: { "src/cell/cell*": { lines: 70, }, "src/common/clipboard*": { lines: 60, statements: 60, }, "src/headers/headerCell*": { lines: 70, statements: 70, }, }, }); </s> remove "table.bundle": [ </s> add table: [ </s> remove "core.bundle": [ </s> add core: [ </s> remove "labs.bundle": [ </s> add labs: [
loader: "istanbul-instrumenter-loader", options: { esModules: true, },
}, { enforce: "post", test: /src\/.*\.tsx?$/, loader: "istanbul-instrumenter-loader", options: { esModules: true, }, }, { test: /\.(eot|ttf|woff|woff2|svg|png)$/, loader: require.resolve("file-loader"), },
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/karma-build-scripts/webpack.karma.config.js
const { createKarmaConfig } = require("@blueprintjs/karma-build-scripts"); const path = require("path"); module.exports = function (config) { const baseConfig = createKarmaConfig(__dirname); config.set(baseConfig); config.set({ // disable coverage reporter reporters: ["mocha"], webpack: Object.assign({}, baseConfig.webpack, {
</s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, }); </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageExcludes: [ "src/accessibility/*", ], }); </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageOverrides: { "src/cell/cell*": { lines: 70, }, "src/common/clipboard*": { lines: 60, statements: 60, }, "src/headers/headerCell*": { lines: 70, statements: 70, }, }, }); </s> remove "datetime.bundle": [ </s> add datetime: [ </s> remove "table.bundle": [ </s> add table: [
const baseConfig = createKarmaConfig({ dirname: __dirname, });
const { createKarmaConfig } = require("@blueprintjs/karma-build-scripts"); const path = require("path"); module.exports = function (config) { const baseConfig = createKarmaConfig({ dirname: __dirname, }); config.set(baseConfig); config.set({ // disable coverage reporter reporters: ["mocha"], webpack: Object.assign({}, baseConfig.webpack, {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/karma.conf.js
"version": "0.13.0", "description": "Incubator for unstable and in-development Blueprint components", "main": "dist/index.js", "module": "dist/esm/index.js", "typings": "dist/index.d.ts", "style": "dist/blueprint-labs.css", "unpkg": "dist/labs.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src",
</s> remove "typings": "dist/index.d.ts", </s> add "typings": "dist/esm/index.d.ts", </s> remove "typings": "dist/index.d.ts", </s> add "typings": "dist/esm/index.d.ts", </s> remove "typings": "dist/index.d.ts", </s> add "module": "dist/esm/index.js", "typings": "dist/esm/index.d.ts", </s> remove "typings": "dist/index.d.ts", </s> add "typings": "dist/esm/index.d.ts", </s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true",
"typings": "dist/esm/index.d.ts",
"version": "0.13.0", "description": "Incubator for unstable and in-development Blueprint components", "main": "dist/index.js", "module": "dist/esm/index.js", "typings": "dist/esm/index.d.ts", "style": "dist/blueprint-labs.css", "unpkg": "dist/labs.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/package.json
"style": "dist/blueprint-labs.css", "unpkg": "dist/labs.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json",
</s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "compile": "npm-run-all -p compile:typescript compile:sass", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile": "npm-run-all -p 'compile:*'", "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", </s> add "dev": "npm-run-all -p 'compile:esm -- --watch' 'compile:css -- --watch'",
"compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true",
"style": "dist/blueprint-labs.css", "unpkg": "dist/labs.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json",
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/package.json
"compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint",
</s>
"dev": "npm-run-all -p 'compile:esm -- --watch' 'compile:css -- --watch'",
"compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:esm -- --watch' 'compile:css -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/package.json
"clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint", "lint:stylelint": "stylelint -s scss 'src/**/*.scss'", "lint:tslint": "tslint '{src,test}/**/*.{ts,tsx}' -c ../tslint-config", "lint-fix": "yarn lint:tslint --fix",
</s>
"clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint", "lint:stylelint": "stylelint -s scss 'src/**/*.scss'", "lint:tslint": "tslint '{src,test}/**/*.{ts,tsx}' -c ../tslint-config", "lint-fix": "yarn lint:tslint --fix",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/package.json
{ "extends": "../../../config/tsconfig.base", "compilerOptions": { "outDir": "../dist" } }
</s>
"outDir": "../dist/esm"
{ "extends": "../../../config/tsconfig.base", "compilerOptions": { "outDir": "../dist/esm" } }
[ "keep", "keep", "keep", "replace", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/src/tsconfig.json
const path = require("path"); module.exports = Object.assign({}, baseConfig, { entry: { "labs.bundle": [ "./src/index.ts" ], }, externals: COMMON_EXTERNALS,
</s> remove "table.bundle": [ </s> add table: [ </s> remove "datetime.bundle": [ </s> add datetime: [ </s> remove "core.bundle": [ </s> add core: [ </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageExcludes: [ "src/accessibility/*", ], }); </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, });
labs: [
const path = require("path"); module.exports = Object.assign({}, baseConfig, { entry: { labs: [ "./src/index.ts" ], }, externals: COMMON_EXTERNALS,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/webpack.config.js
externals: COMMON_EXTERNALS, output: { filename: "[name].js", library: ["Blueprint", "Labs"], libraryTarget: "umd", path: path.resolve(__dirname, "./dist") }, });
</s> remove filename: "[name].js", </s> add filename: "[name].bundle.js", </s> remove filename: "[name].js", </s> add filename: "[name].bundle.js", </s> remove filename: "[name].js", </s> add filename: "[name].bundle.js", </s> remove "table.bundle": [ </s> add table: [ </s> remove "core.bundle": [ </s> add core: [
filename: "[name].bundle.js",
externals: COMMON_EXTERNALS, output: { filename: "[name].bundle.js", library: ["Blueprint", "Labs"], libraryTarget: "umd", path: path.resolve(__dirname, "./dist") }, });
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/labs/webpack.config.js
{ "extends": "../../../config/tsconfig.base.json", "compilerOptions": { "declaration": false, "lib": ["dom", "es5", "es6"], "noImplicitAny": false, "noUnusedLocals": false, "noUnusedParameters": false, "outDir": "../dist"
</s> remove "declaration": false, "lib": ["dom", "es5", "es6"] </s> add "lib": ["dom", "es5", "es6"], "outDir": "../dist" </s> remove "declaration": false, </s> add </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm" </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm" </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm"
{ "extends": "../../../config/tsconfig.base.json", "compilerOptions": { "lib": ["dom", "es5", "es6"], "noImplicitAny": false, "noUnusedLocals": false, "noUnusedParameters": false, "outDir": "../dist"
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/landing-app/src/tsconfig.json
* * Licensed under the terms of the LICENSE file distributed with this project. */ import defaults = require("lodash/defaults"); /** * Simple typed storage API for a JSON serializable object in web local storage * or session storage. */
</s> remove module.exports = function createKarmaConfig(dirname) { </s> add /** * @param dirname string * @param coverageExcludes string[] * @param coverageOverrides { [glob: string]: object } */ module.exports = function createKarmaConfig({ dirname, coverageExcludes, coverageOverrides }) { </s> remove import { Browser } from "@blueprintjs/core/dist/compatibility"; </s> add import { Browser } from "@blueprintjs/core/dist/esm/compatibility"; </s> remove /* istanbul ignore next */ </s> add </s> remove // this is basically meaningless to unit test; it requires manual UI testing /* istanbul ignore next */ </s> add
import { defaults } from "lodash";
* * Licensed under the terms of the LICENSE file distributed with this project. */ import { defaults } from "lodash"; /** * Simple typed storage API for a JSON serializable object in web local storage * or session storage. */
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table-dev-app/src/localStore.ts
{ "extends": "../../../config/tsconfig.base.json", "compilerOptions": { "declaration": false, "lib": ["dom", "es5", "es6"] } }
</s> remove "declaration": false, </s> add </s> remove "declaration": false, </s> add </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm" </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm" </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm"
"lib": ["dom", "es5", "es6"], "outDir": "../dist"
{ "extends": "../../../config/tsconfig.base.json", "compilerOptions": { "lib": ["dom", "es5", "es6"], "outDir": "../dist" "lib": ["dom", "es5", "es6"], "outDir": "../dist" } }
[ "keep", "keep", "keep", "replace", "replace", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table-dev-app/src/tsconfig.json
const { createKarmaConfig } = require("@blueprintjs/karma-build-scripts"); const path = require("path"); module.exports = function (config) { const baseConfig = createKarmaConfig(__dirname); config.set(baseConfig); config.set({ webpack: Object.assign({}, baseConfig.webpack, { entry: { core: path.resolve(__dirname, "test/index.ts"),
</s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, }); </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, }); </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageExcludes: [ "src/accessibility/*", ], }); </s> remove "core.bundle": [ </s> add core: [ </s> remove "table.bundle": [ </s> add table: [
const baseConfig = createKarmaConfig({ dirname: __dirname, coverageOverrides: { "src/cell/cell*": { lines: 70, }, "src/common/clipboard*": { lines: 60, statements: 60, }, "src/headers/headerCell*": { lines: 70, statements: 70, }, }, });
const { createKarmaConfig } = require("@blueprintjs/karma-build-scripts"); const path = require("path"); module.exports = function (config) { const baseConfig = createKarmaConfig({ dirname: __dirname, coverageOverrides: { "src/cell/cell*": { lines: 70, }, "src/common/clipboard*": { lines: 60, statements: 60, }, "src/headers/headerCell*": { lines: 70, statements: 70, }, }, }); config.set(baseConfig); config.set({ webpack: Object.assign({}, baseConfig.webpack, { entry: { core: path.resolve(__dirname, "test/index.ts"),
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/karma.conf.js
"version": "1.30.0", "description": "Scalable interactive table component", "main": "dist/index.js", "module": "dist/esm/index.js", "typings": "dist/index.d.ts", "style": "dist/table.css", "unpkg": "dist/table.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src",
</s> remove "typings": "dist/index.d.ts", </s> add "typings": "dist/esm/index.d.ts", </s> remove "typings": "dist/index.d.ts", </s> add "typings": "dist/esm/index.d.ts", </s> remove "typings": "dist/index.d.ts", </s> add "module": "dist/esm/index.js", "typings": "dist/esm/index.d.ts", </s> remove "typings": "dist/index.d.ts", </s> add "typings": "dist/esm/index.d.ts", </s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true",
"typings": "dist/esm/index.d.ts",
"version": "1.30.0", "description": "Scalable interactive table component", "main": "dist/index.js", "module": "dist/esm/index.js", "typings": "dist/esm/index.d.ts", "style": "dist/table.css", "unpkg": "dist/table.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/package.json
"style": "dist/table.css", "unpkg": "dist/table.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json",
</s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "compile": "npm-run-all -p compile:typescript compile:sass", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> add "compile": "npm-run-all -p 'compile:*'", "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", </s> remove "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", </s> add "dev": "npm-run-all -p 'compile:esm -- --watch' 'compile:css -- --watch'",
"compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true",
"style": "dist/table.css", "unpkg": "dist/table.bundle.js", "scripts": { "compile": "npm-run-all -p 'compile:*'", "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "compile:esm": "tsc -p ./src", "compile:cjs": "tsc -p ./src/tsconfig.cjs.json", "compile:css": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json",
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/package.json
"compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint",
</s>
"dev": "npm-run-all -p 'compile:esm -- --watch' 'compile:css -- --watch'",
"compile": "npm-run-all -p 'compile:*'", "compile:typescript": "tsc -p ./src", "compile:sass": "node-sass --importer ../../node_modules/node-sass-package-importer/dist/cli.js --recursive src --output dist/ --source-map true", "clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:esm -- --watch' 'compile:css -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/package.json
"clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:esm": "tsc -p ./src/tsconfig.esm.json", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint", "lint:stylelint": "stylelint -s scss 'src/**/*.scss'", "lint:tslint": "tslint '{src,test}/**/*.{ts,tsx}' -c ../tslint-config", "lint-fix": "yarn lint:tslint --fix",
</s>
"clean": "rm -rf dist/*", "dev": "npm-run-all -p 'compile:typescript -- --watch' 'compile:sass -- --watch'", "dist": "npm-run-all -s 'dist:*'", "dist:bundle": "NODE_ENV=production webpack", "dist:verify": "assert-package-layout", "lint": "npm-run-all -p lint:stylelint lint:tslint", "lint:stylelint": "stylelint -s scss 'src/**/*.scss'", "lint:tslint": "tslint '{src,test}/**/*.{ts,tsx}' -c ../tslint-config", "lint-fix": "yarn lint:tslint --fix",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/package.json
"lint": "npm-run-all -p lint:stylelint lint:tslint", "lint:stylelint": "stylelint -s scss 'src/**/*.scss'", "lint:tslint": "tslint '{src,test}/**/*.{ts,tsx}' -c ../tslint-config", "lint-fix": "yarn lint:tslint --fix", "test": "npm-run-all -s compile:typescript test:pre -p test:karma test:iso", "test:pre": "tsc -p ./test", "test:karma": "karma start", "test:iso": "mocha test/isotest.js", "verify": "npm-run-all compile -p dist test lint" },
</s>
"test": "npm-run-all -s compile:cjs test:pre -p test:karma test:iso",
"lint": "npm-run-all -p lint:stylelint lint:tslint", "lint:stylelint": "stylelint -s scss 'src/**/*.scss'", "lint:tslint": "tslint '{src,test}/**/*.{ts,tsx}' -c ../tslint-config", "lint-fix": "yarn lint:tslint --fix", "test": "npm-run-all -s compile:cjs test:pre -p test:karma test:iso", "test:pre": "tsc -p ./test", "test:karma": "karma start", "test:iso": "mocha test/isotest.js", "verify": "npm-run-all compile -p dist test lint" },
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/package.json
{ "extends": "../../../config/tsconfig.base", "compilerOptions": { "lib": ["dom", "es5", "es6"], "outDir": "../dist" } }
</s> remove "declaration": false, "lib": ["dom", "es5", "es6"] </s> add "lib": ["dom", "es5", "es6"], "outDir": "../dist" </s> remove "declaration": false, </s> add </s> remove "declaration": false, </s> add </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm" </s> remove "outDir": "../dist" </s> add "outDir": "../dist/esm"
"outDir": "../dist/esm"
{ "extends": "../../../config/tsconfig.base", "compilerOptions": { "lib": ["dom", "es5", "es6"], "outDir": "../dist/esm" } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/src/tsconfig.json
// tslint:disable max-classes-per-file // tslint:disable-next-line:no-submodule-imports import { Browser } from "@blueprintjs/core/dist/compatibility"; import * as React from "react"; import * as ReactDOM from "react-dom"; export type MouseEventType = "click" | "mousedown" | "mouseup" | "mousemove" | "mouseenter" | "mouseleave"; export type KeyboardEventType = "keypress" | "keydown" | "keyup";
</s> remove import { getDefaultMaxTime, getDefaultMinTime } from "@blueprintjs/datetime/dist/timePicker"; </s> add import { getDefaultMaxTime, getDefaultMinTime } from "@blueprintjs/datetime/dist/esm/timePicker"; </s> remove import defaults = require("lodash/defaults"); </s> add import { defaults } from "lodash"; </s> remove /* istanbul ignore next */ </s> add </s> remove module.exports = function createKarmaConfig(dirname) { </s> add /** * @param dirname string * @param coverageExcludes string[] * @param coverageOverrides { [glob: string]: object } */ module.exports = function createKarmaConfig({ dirname, coverageExcludes, coverageOverrides }) {
import { Browser } from "@blueprintjs/core/dist/esm/compatibility";
// tslint:disable max-classes-per-file // tslint:disable-next-line:no-submodule-imports import { Browser } from "@blueprintjs/core/dist/esm/compatibility"; import * as React from "react"; import * as ReactDOM from "react-dom"; export type MouseEventType = "click" | "mousedown" | "mouseup" | "mousemove" | "mouseenter" | "mouseleave"; export type KeyboardEventType = "keypress" | "keydown" | "keyup";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/test/harness.ts
const path = require("path"); module.exports = Object.assign({}, baseConfig, { entry: { "table.bundle": [ "./src/index.ts" ], }, externals: COMMON_EXTERNALS,
</s> remove "labs.bundle": [ </s> add labs: [ </s> remove "datetime.bundle": [ </s> add datetime: [ </s> remove "core.bundle": [ </s> add core: [ </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageExcludes: [ "src/accessibility/*", ], }); </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, });
table: [
const path = require("path"); module.exports = Object.assign({}, baseConfig, { entry: { table: [ "./src/index.ts" ], }, externals: COMMON_EXTERNALS,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/webpack.config.js
externals: COMMON_EXTERNALS, output: { filename: "[name].js", library: ["Blueprint", "Table"], libraryTarget: "umd", path: path.resolve(__dirname, "./dist") }, });
</s> remove filename: "[name].js", </s> add filename: "[name].bundle.js", </s> remove filename: "[name].js", </s> add filename: "[name].bundle.js", </s> remove filename: "[name].js", </s> add filename: "[name].bundle.js", </s> remove "table.bundle": [ </s> add table: [ </s> remove "core.bundle": [ </s> add core: [
filename: "[name].bundle.js",
externals: COMMON_EXTERNALS, output: { filename: "[name].bundle.js", library: ["Blueprint", "Table"], libraryTarget: "umd", path: path.resolve(__dirname, "./dist") }, });
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/table/webpack.config.js
module.exports = { baseConfig, COMMON_EXTERNALS: { "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", }, };
</s> remove "datetime.bundle": [ </s> add datetime: [ </s> remove "labs.bundle": [ </s> add labs: [ </s> remove "core.bundle": [ </s> add core: [ </s> remove "table.bundle": [ </s> add table: [ </s> remove const baseConfig = createKarmaConfig(__dirname); </s> add const baseConfig = createKarmaConfig({ dirname: __dirname, coverageOverrides: { "src/cell/cell*": { lines: 70, }, "src/common/clipboard*": { lines: 60, statements: 60, }, "src/headers/headerCell*": { lines: 70, statements: 70, }, }, });
"@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether",
module.exports = { baseConfig, COMMON_EXTERNALS: { "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", "@blueprintjs/core": "var Blueprint.Core", "@blueprintjs/datetime": "var Blueprint.Datetime", "@blueprintjs/labs": "var Blueprint.Labs", "@blueprintjs/table": "var Blueprint.Table", "classnames": "classNames", "dom4": "window", "es6-shim": "window", "jquery": "$", "moment": "moment", "moment-timezone": "moment", "react": "React", "react-addons-css-transition-group": "React.addons.CSSTransitionGroup", "react-day-picker": "DayPicker", "react-dom": "ReactDOM", "tether": "Tether", }, };
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep" ]
Emit ES modules in dev scripts, CJS in CI scripts (#1867)
https://github.com/palantir/blueprint/commit/ade126aca2b94adc1504f3d00f6586bb58e205ba
packages/webpack-build-scripts/index.js
}; private handleDocumentClick = (e: MouseEvent) => { const { canOutsideClickClose, isOpen, onClose } = this.props; const eventTarget = e.target as HTMLElement; const stackIndex = Overlay.openStack.indexOf(this); const isClickInThisOverlayOrDescendant = Overlay.openStack .slice(stackIndex) .some(({ containerElement: elem }) => {
</s> remove e.target instanceof Node && !this.containerElement.contains(e.target as HTMLElement) </s> add eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement)
// get the actually target even if we are in an open mode Shadow DOM const eventTarget = (e.composed ? e.composedPath()[0] : e.target) as HTMLElement;
}; private handleDocumentClick = (e: MouseEvent) => { const { canOutsideClickClose, isOpen, onClose } = this.props; // get the actually target even if we are in an open mode Shadow DOM const eventTarget = (e.composed ? e.composedPath()[0] : e.target) as HTMLElement; const stackIndex = Overlay.openStack.indexOf(this); const isClickInThisOverlayOrDescendant = Overlay.openStack .slice(stackIndex) .some(({ containerElement: elem }) => {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[core] fix(Overlay): handle document click/focus in Shadow DOM (#4218)
https://github.com/palantir/blueprint/commit/ae0d446b3a57bf09b1a835d4b3273ab40aeee50f
packages/core/src/components/overlay/overlay.tsx
}; private handleDocumentFocus = (e: FocusEvent) => { if ( this.props.enforceFocus && this.containerElement != null && eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement) ) {
</s> remove const eventTarget = e.target as HTMLElement; </s> add // get the actually target even if we are in an open mode Shadow DOM const eventTarget = (e.composed ? e.composedPath()[0] : e.target) as HTMLElement; </s> remove e.target instanceof Node && !this.containerElement.contains(e.target as HTMLElement) </s> add eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement)
// get the actually target even if we are in an open mode Shadow DOM const eventTarget = e.composed ? e.composedPath()[0] : e.target;
}; private handleDocumentFocus = (e: FocusEvent) => { // get the actually target even if we are in an open mode Shadow DOM const eventTarget = e.composed ? e.composedPath()[0] : e.target; if ( this.props.enforceFocus && this.containerElement != null && eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement) ) {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
[core] fix(Overlay): handle document click/focus in Shadow DOM (#4218)
https://github.com/palantir/blueprint/commit/ae0d446b3a57bf09b1a835d4b3273ab40aeee50f
packages/core/src/components/overlay/overlay.tsx
private handleDocumentFocus = (e: FocusEvent) => { if ( this.props.enforceFocus && this.containerElement != null && e.target instanceof Node && !this.containerElement.contains(e.target as HTMLElement) ) { // prevent default focus behavior (sometimes auto-scrolls the page) e.preventDefault(); e.stopImmediatePropagation(); this.bringFocusInsideOverlay();
</s> remove const eventTarget = e.target as HTMLElement; </s> add // get the actually target even if we are in an open mode Shadow DOM const eventTarget = (e.composed ? e.composedPath()[0] : e.target) as HTMLElement;
eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement)
private handleDocumentFocus = (e: FocusEvent) => { if ( this.props.enforceFocus && this.containerElement != null && eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement) eventTarget instanceof Node && !this.containerElement.contains(eventTarget as HTMLElement) ) { // prevent default focus behavior (sometimes auto-scrolls the page) e.preventDefault(); e.stopImmediatePropagation(); this.bringFocusInsideOverlay();
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[core] fix(Overlay): handle document click/focus in Shadow DOM (#4218)
https://github.com/palantir/blueprint/commit/ae0d446b3a57bf09b1a835d4b3273ab40aeee50f
packages/core/src/components/overlay/overlay.tsx
*/ import { CLAMP_MIN_MAX } from "./errors"; // only accessible within this file, so use `Utils.isNodeEnv` from the outside. declare var process: { env: any }; /** Returns whether `process.env.NODE_ENV` exists and equals `env`. */ export function isNodeEnv(env: string) { return typeof process !== "undefined" && process.env && process.env.NODE_ENV === env;
</s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */ </s> remove * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. </s> add * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead.
export * from "./utils/compareUtils";
*/ import { CLAMP_MIN_MAX } from "./errors"; export * from "./utils/compareUtils"; // only accessible within this file, so use `Utils.isNodeEnv` from the outside. declare var process: { env: any }; /** Returns whether `process.env.NODE_ENV` exists and equals `env`. */ export function isNodeEnv(env: string) { return typeof process !== "undefined" && process.env && process.env.NODE_ENV === env;
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
export function isFunction(value: any): value is Function { return typeof value === "function"; } /** Safely invoke the function with the given arguments, if it is indeed a function, and return its value. */ export function safeInvoke<R>(func: (() => R) | undefined): R; export function safeInvoke<A, R>(func: ((arg1: A) => R) | undefined, arg1: A): R; export function safeInvoke<A, B, R>(func: ((arg1: A, arg2: B) => R) | undefined, arg1: A, arg2: B): R; export function safeInvoke<A, B, C, R>( func: ((arg1: A, arg2: B, arg3: C) => R) | undefined,
</s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { </s> add const throttledFunc = _throttleHelper(undefined, undefined, (event: Event) => { </s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */ </s> remove * Throttle an event on an EventTarget by wrapping it in a `requestAnimationFrame` call. * Returns the event handler that was bound to given eventName so you can clean up after yourself. </s> add * Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself. </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual,
/** * Safely invoke the function with the given arguments, if it is indeed a * function, and return its value. */
export function isFunction(value: any): value is Function { return typeof value === "function"; } /** * Safely invoke the function with the given arguments, if it is indeed a * function, and return its value. */ export function safeInvoke<R>(func: (() => R) | undefined): R; export function safeInvoke<A, R>(func: ((arg1: A) => R) | undefined, arg1: A): R; export function safeInvoke<A, B, R>(func: ((arg1: A, arg2: B) => R) | undefined, arg1: A, arg2: B): R; export function safeInvoke<A, B, C, R>( func: ((arg1: A, arg2: B, arg3: C) => R) | undefined,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
return element === testElement || element.contains(testElement); } /** * Returns the difference in length between two arrays. A `null` argument is considered an empty list. * The return value will be positive if `a` is longer than `b`, negative if the opposite is true, * and zero if their lengths are equal. */ export function arrayLengthCompare(a: any[] = [], b: any[] = []) { return a.length - b.length; }
</s> remove * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. </s> add * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove * This is useful to correct for floating point precision issues, less useful for integers. </s> add * This is useful to correct for floating point precision issues, less useful * for integers.
* Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal.
return element === testElement || element.contains(testElement); } /** * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. */ export function arrayLengthCompare(a: any[] = [], b: any[] = []) { return a.length - b.length; }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
} /** * Returns true if the two numbers are within the given tolerance of each other. * This is useful to correct for floating point precision issues, less useful for integers. */ export function approxEqual(a: number, b: number, tolerance = 0.00001) { return Math.abs(a - b) <= tolerance; }
</s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */ </s> remove * Returns the difference in length between two arrays. A `null` argument is considered an empty list. * The return value will be positive if `a` is longer than `b`, negative if the opposite is true, * and zero if their lengths are equal. </s> add * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); },
* This is useful to correct for floating point precision issues, less useful * for integers.
} /** * Returns true if the two numbers are within the given tolerance of each other. * This is useful to correct for floating point precision issues, less useful * for integers. */ export function approxEqual(a: number, b: number, tolerance = 0.00001) { return Math.abs(a - b) <= tolerance; }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
export function approxEqual(a: number, b: number, tolerance = 0.00001) { return Math.abs(a - b) <= tolerance; } /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ export function clamp(val: number, min: number, max: number) { if (val == null) { return val; } if (max < min) {
</s> remove * This is useful to correct for floating point precision issues, less useful for integers. </s> add * This is useful to correct for floating point precision issues, less useful * for integers. </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove BlueprintUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> remove BlueprintUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> remove * Returns the difference in length between two arrays. A `null` argument is considered an empty list. * The return value will be positive if `a` is longer than `b`, negative if the opposite is true, * and zero if their lengths are equal. </s> add * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal.
/** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */
export function approxEqual(a: number, b: number, tolerance = 0.00001) { return Math.abs(a - b) <= tolerance; } /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */ export function clamp(val: number, min: number, max: number) { if (val == null) { return val; } if (max < min) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
return num.toString().split(".")[1].length; } /** * Throttle an event on an EventTarget by wrapping it in a `requestAnimationFrame` call. * Returns the event handler that was bound to given eventName so you can clean up after yourself. * @see https://developer.mozilla.org/en-US/docs/Web/Events/scroll */ export function throttleEvent(target: EventTarget, eventName: string, newEventName: string) { const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { target.dispatchEvent(new CustomEvent(newEventName, event));
</s> remove const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { </s> add const throttledFunc = _throttleHelper(undefined, undefined, (event: Event) => { </s> remove * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns the throttled * function. </s> add * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns * the throttled function. </s> remove /** Safely invoke the function with the given arguments, if it is indeed a function, and return its value. */ </s> add /** * Safely invoke the function with the given arguments, if it is indeed a * function, and return its value. */ </s> remove * Returns the difference in length between two arrays. A `null` argument is considered an empty list. * The return value will be positive if `a` is longer than `b`, negative if the opposite is true, * and zero if their lengths are equal. </s> add * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. </s> remove import { Utils } from "../common/utils"; </s> add
* Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself.
return num.toString().split(".")[1].length; } /** * Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself. * Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself. * @see https://developer.mozilla.org/en-US/docs/Web/Events/scroll */ export function throttleEvent(target: EventTarget, eventName: string, newEventName: string) { const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { target.dispatchEvent(new CustomEvent(newEventName, event));
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
* Returns the event handler that was bound to given eventName so you can clean up after yourself. * @see https://developer.mozilla.org/en-US/docs/Web/Events/scroll */ export function throttleEvent(target: EventTarget, eventName: string, newEventName: string) { const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { target.dispatchEvent(new CustomEvent(newEventName, event)); }); target.addEventListener(eventName, throttledFunc); return throttledFunc; }
</s> remove * Throttle an event on an EventTarget by wrapping it in a `requestAnimationFrame` call. * Returns the event handler that was bound to given eventName so you can clean up after yourself. </s> add * Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself. </s> remove const throttledFunc = throttleHelper( </s> add const throttledFunc = _throttleHelper( </s> remove * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns the throttled * function. </s> add * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns * the throttled function. </s> remove /** Safely invoke the function with the given arguments, if it is indeed a function, and return its value. */ </s> add /** * Safely invoke the function with the given arguments, if it is indeed a * function, and return its value. */
const throttledFunc = _throttleHelper(undefined, undefined, (event: Event) => {
* Returns the event handler that was bound to given eventName so you can clean up after yourself. * @see https://developer.mozilla.org/en-US/docs/Web/Events/scroll */ export function throttleEvent(target: EventTarget, eventName: string, newEventName: string) { const throttledFunc = _throttleHelper(undefined, undefined, (event: Event) => { target.dispatchEvent(new CustomEvent(newEventName, event)); }); target.addEventListener(eventName, throttledFunc); return throttledFunc; }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
preventDefault?: boolean; } /** * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns the throttled * function. * @see https://www.html5rocks.com/en/tutorials/speed/animations/ */ export function throttleReactEventCallback( callback: (event: React.SyntheticEvent<any>, ...otherArgs: any[]) => any, options: IThrottledReactEventOptions = {},
</s> remove * Throttle an event on an EventTarget by wrapping it in a `requestAnimationFrame` call. * Returns the event handler that was bound to given eventName so you can clean up after yourself. </s> add * Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself. </s> remove const throttledFunc = throttleHelper( </s> add const throttledFunc = _throttleHelper( </s> remove const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { </s> add const throttledFunc = _throttleHelper(undefined, undefined, (event: Event) => { </s> remove * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. </s> add * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. </s> remove /** Safely invoke the function with the given arguments, if it is indeed a function, and return its value. */ </s> add /** * Safely invoke the function with the given arguments, if it is indeed a * function, and return its value. */
* Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns * the throttled function.
preventDefault?: boolean; } /** * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns * the throttled function. * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns * the throttled function. * @see https://www.html5rocks.com/en/tutorials/speed/animations/ */ export function throttleReactEventCallback( callback: (event: React.SyntheticEvent<any>, ...otherArgs: any[]) => any, options: IThrottledReactEventOptions = {},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
export function throttleReactEventCallback( callback: (event: React.SyntheticEvent<any>, ...otherArgs: any[]) => any, options: IThrottledReactEventOptions = {}, ) { const throttledFunc = throttleHelper( (event2: React.SyntheticEvent<any>) => { if (options.preventDefault) { event2.preventDefault(); } },
</s> remove * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns the throttled * function. </s> add * Throttle a callback by wrapping it in a `requestAnimationFrame` call. Returns * the throttled function. </s> remove // prevent React from reclaiming the event object before we reference it </s> add // prevent React from reclaiming the event object before we // reference it </s> remove type ThrottleHelperCallback = (...args: any[]) => void; function throttleHelper( onBeforeIsRunningCheck: ThrottleHelperCallback, onAfterIsRunningCheck: ThrottleHelperCallback, onAnimationFrameRequested: ThrottleHelperCallback, </s> add function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, </s> remove const throttledFunc = throttleHelper(undefined, undefined, (event: Event) => { </s> add const throttledFunc = _throttleHelper(undefined, undefined, (event: Event) => { </s> remove describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); </s> add
const throttledFunc = _throttleHelper(
export function throttleReactEventCallback( callback: (event: React.SyntheticEvent<any>, ...otherArgs: any[]) => any, options: IThrottledReactEventOptions = {}, ) { const throttledFunc = _throttleHelper( (event2: React.SyntheticEvent<any>) => { if (options.preventDefault) { event2.preventDefault(); } },
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
event2.preventDefault(); } }, (event2: React.SyntheticEvent<any>) => { // prevent React from reclaiming the event object before we reference it event2.persist(); }, (event2: React.SyntheticEvent<any>, ...otherArgs2: any[]) => { callback(event2, ...otherArgs2); },
</s> remove const throttledFunc = throttleHelper( </s> add const throttledFunc = _throttleHelper( </s> remove describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); </s> add </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove type ThrottleHelperCallback = (...args: any[]) => void; function throttleHelper( onBeforeIsRunningCheck: ThrottleHelperCallback, onAfterIsRunningCheck: ThrottleHelperCallback, onAnimationFrameRequested: ThrottleHelperCallback, </s> add function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, </s> remove * Throttle an event on an EventTarget by wrapping it in a `requestAnimationFrame` call. * Returns the event handler that was bound to given eventName so you can clean up after yourself. </s> add * Throttle an event on an EventTarget by wrapping it in a * `requestAnimationFrame` call. Returns the event handler that was bound to * given eventName so you can clean up after yourself.
// prevent React from reclaiming the event object before we // reference it
event2.preventDefault(); } }, (event2: React.SyntheticEvent<any>) => { // prevent React from reclaiming the event object before we // reference it event2.persist(); }, (event2: React.SyntheticEvent<any>, ...otherArgs2: any[]) => { callback(event2, ...otherArgs2); },
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
); return throttledFunc; } type ThrottleHelperCallback = (...args: any[]) => void; function throttleHelper( onBeforeIsRunningCheck: ThrottleHelperCallback, onAfterIsRunningCheck: ThrottleHelperCallback, onAnimationFrameRequested: ThrottleHelperCallback, ) { let isRunning = false; const func = (...args: any[]) => { // don't use safeInvoke, because we might have more than its max number of typed params if (isFunction(onBeforeIsRunningCheck)) {
</s> remove // don't use safeInvoke, because we might have more than its max number of typed params </s> add // don't use safeInvoke, because we might have more than its max number // of typed params </s> remove const throttledFunc = throttleHelper( </s> add const throttledFunc = _throttleHelper( </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys,
function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void,
); return throttledFunc; } function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, ) { let isRunning = false; const func = (...args: any[]) => { // don't use safeInvoke, because we might have more than its max number of typed params if (isFunction(onBeforeIsRunningCheck)) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
onAnimationFrameRequested: ThrottleHelperCallback, ) { let isRunning = false; const func = (...args: any[]) => { // don't use safeInvoke, because we might have more than its max number of typed params if (isFunction(onBeforeIsRunningCheck)) { onBeforeIsRunningCheck(...args); } if (isRunning) {
</s> remove type ThrottleHelperCallback = (...args: any[]) => void; function throttleHelper( onBeforeIsRunningCheck: ThrottleHelperCallback, onAfterIsRunningCheck: ThrottleHelperCallback, onAnimationFrameRequested: ThrottleHelperCallback, </s> add function _throttleHelper( onBeforeIsRunningCheck: (...args: any[]) => void, onAfterIsRunningCheck: (...args: any[]) => void, onAnimationFrameRequested: (...args: any[]) => void, </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove const throttledFunc = throttleHelper( </s> add const throttledFunc = _throttleHelper( </s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */
// don't use safeInvoke, because we might have more than its max number // of typed params
onAnimationFrameRequested: ThrottleHelperCallback, ) { let isRunning = false; const func = (...args: any[]) => { // don't use safeInvoke, because we might have more than its max number // of typed params if (isFunction(onBeforeIsRunningCheck)) { onBeforeIsRunningCheck(...args); } if (isRunning) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/src/common/utils.ts
* and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { assert } from "chai"; import { Utils } from "../../src"; describe("Utils", () => { it("isFunction", () => { assert.isTrue(Utils.isFunction(() => 3)); assert.isFalse(Utils.isFunction(undefined));
</s> remove import { IKeyBlacklist, IKeyWhitelist, Utils } from "../src/common/utils"; </s> add import { Utils } from "../src/common/utils"; </s> remove describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); </s> add </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core";
import * as Utils from "../../src/common/utils";
* and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { assert } from "chai"; import * as Utils from "../../src/common/utils"; describe("Utils", () => { it("isFunction", () => { assert.isTrue(Utils.isFunction(() => 3)); assert.isFalse(Utils.isFunction(undefined));
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/test/common/utilsTests.ts
import "./collapsible-list/collapsibleListTests"; import "./common/propsTests.ts"; import "./common/tetherUtilsTests.ts"; import "./common/utilsTests.ts"; import "./context-menu/contextMenuTests"; import "./controls/controlsTests"; import "./controls/inputGroupTests";
</s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "./common/utils"; </s> add </s> remove import { Keys } from "@blueprintjs/core"; </s> add import { Keys, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption, Utils } from "../src"; </s> add import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption } from "../src"; </s> remove import { Utils } from "../common/utils"; </s> add
import "./common/utils/compareUtilsTests.ts";
import "./collapsible-list/collapsibleListTests"; import "./common/propsTests.ts"; import "./common/tetherUtilsTests.ts"; import "./common/utils/compareUtilsTests.ts"; import "./common/utilsTests.ts"; import "./context-menu/contextMenuTests"; import "./controls/controlsTests"; import "./controls/inputGroupTests";
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/core/test/index.ts
import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; import { LoadableContent } from "../common/loadableContent";
</s> remove import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; </s> add import { Classes as CoreClasses, IIntentProps, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add
import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; import { LoadableContent } from "../common/loadableContent";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/cell/cell.tsx
import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; import { LoadableContent } from "../common/loadableContent"; export interface ICellProps extends IIntentProps, IProps { key?: string;
</s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add
import { Classes as CoreClasses, IIntentProps, IProps, Utils as CoreUtils } from "@blueprintjs/core";
import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { Classes as CoreClasses, IIntentProps, IProps, Utils as CoreUtils } from "@blueprintjs/core"; import { LoadableContent } from "../common/loadableContent"; export interface ICellProps extends IIntentProps, IProps { key?: string;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/cell/cell.tsx
public shouldComponentUpdate(nextProps: ICellProps) { // deeply compare "style," because a new but identical object might have been provided. return ( !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) ); } public render() { const { style, intent, interactive, loading, tooltip, truncated, className, wrapText } = this.props;
</s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove !Utils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !Utils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, Utils.shallowCompareKeys) || !Utils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) </s> add !CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) </s> remove !Utils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !Utils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) </s> add !CoreUtils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !CoreUtils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides)
!CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style)
public shouldComponentUpdate(nextProps: ICellProps) { // deeply compare "style," because a new but identical object might have been provided. return ( !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) ); } public render() { const { style, intent, interactive, loading, tooltip, truncated, className, wrapText } = this.props;
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/cell/cell.tsx
import { EditableText, Utils as CoreUtils } from "@blueprintjs/core"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { Draggable } from "../interactions/draggable"; import { Cell, ICellProps } from "./cell"; export interface IEditableCellProps extends ICellProps { /**
</s> remove import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; </s> add import { Classes as CoreClasses, IIntentProps, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add
import { EditableText, Utils as CoreUtils } from "@blueprintjs/core"; import * as Classes from "../common/classes"; import { Draggable } from "../interactions/draggable"; import { Cell, ICellProps } from "./cell"; export interface IEditableCellProps extends ICellProps { /**
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/cell/editableCell.tsx
} public shouldComponentUpdate(nextProps: IEditableCellProps, nextState: IEditableCellState) { return ( !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) ); } public componentWillReceiveProps(nextProps: IEditableCellProps) { const { value } = nextProps;
</s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !Utils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !Utils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !Utils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> remove let shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !Utils.shallowCompareKeys(this.state, nextState); </s> add let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState);
!CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"])
} public shouldComponentUpdate(nextProps: IEditableCellProps, nextState: IEditableCellState) { return ( !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) ); } public componentWillReceiveProps(nextProps: IEditableCellProps) { const { value } = nextProps;
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/cell/editableCell.tsx
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; /** * Re-declare matching types from the classnames library;
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core";
import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; /** * Re-declare matching types from the classnames library;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
const CSS_FONT_PROPERTIES = ["font-style", "font-variant", "font-weight", "font-size", "font-family"]; export interface IKeyWhitelist<T> { include: Array<keyof T>; } export interface IKeyBlacklist<T> { exclude: Array<keyof T>; }
</s> remove return Object.keys(keySet) as Array<keyof T>; } </s> add /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, }; </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys,
// the functions using these interfaces now live in core. it's not clear how to // import interfaces from core and re-export them here, so just redefine them.
const CSS_FONT_PROPERTIES = ["font-style", "font-variant", "font-weight", "font-size", "font-family"]; // the functions using these interfaces now live in core. it's not clear how to // import interfaces from core and re-export them here, so just redefine them. export interface IKeyWhitelist<T> { include: Array<keyof T>; } export interface IKeyBlacklist<T> { exclude: Array<keyof T>; }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
} return value; }, /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, /** * When reordering a contiguous block of rows or columns to a new index, we show a preview guide * at the absolute index in the original ordering but emit the new index in the reordered list. * This function converts an absolute "guide" index to a relative "reordered" index. *
</s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, </s> remove return Object.keys(keySet) as Array<keyof T>; } </s> add /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, };
} return value; }, /** * When reordering a contiguous block of rows or columns to a new index, we show a preview guide * at the absolute index in the original ordering but emit the new index in the reordered list. * This function converts an absolute "guide" index to a relative "reordered" index. *
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
return event.button === 0; }, /** * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead.
</s> remove * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. </s> add * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove return Object.keys(keySet) as Array<keyof T>; } </s> add /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, }; </s> remove * Returns the difference in length between two arrays. A `null` argument is considered an empty list. * The return value will be positive if `a` is longer than `b`, negative if the opposite is true, * and zero if their lengths are equal. </s> add * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); },
// these functions used to live here but now live in core. since these Utils // are in the public API, we provide facades here - complete with function // descriptions - so as to make the refactor invisible externally.
return event.button === 0; }, // these functions used to live here but now live in core. since these Utils // are in the public API, we provide facades here - complete with function // descriptions - so as to make the refactor invisible externally. /** * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead.
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
return event.button === 0; }, /** * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. */ arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true;
</s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove * Returns the difference in length between two arrays. A `null` argument is considered an empty list. * The return value will be positive if `a` is longer than `b`, negative if the opposite is true, * and zero if their lengths are equal. </s> add * Returns the difference in length between two arrays. A `null` argument is * considered an empty list. The return value will be positive if `a` is longer * than `b`, negative if the opposite is true, and zero if their lengths are * equal. </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys,
* Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead.
return event.button === 0; }, /** * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true;
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
/** * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. */ arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) {
</s> remove * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. </s> add * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */
arraysEqual: CoreUtils.arraysEqual,
/** * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. */ arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, arraysEqual: CoreUtils.arraysEqual, /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
} }, }; /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB);
</s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, </s> remove return Object.keys(keySet) as Array<keyof T>; } </s> add /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, };
/** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys,
} }, }; /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB);
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
})); return unequalKeyValues; } function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); return Object.keys(keySet) as Array<keyof T>;
</s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove return Object.keys(keySet) as Array<keyof T>; } </s> add /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, }; </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add
/** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); },
})); return unequalKeyValues; } /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); return Object.keys(keySet) as Array<keyof T>;
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); return Object.keys(keySet) as Array<keyof T>; }
</s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, </s> remove return Object.keys(keySet) as Array<keyof T>; } </s> add /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, }; </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add
/** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); },
function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, return Object.keys(keySet) as Array<keyof T>; }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); return Object.keys(keySet) as Array<keyof T>; }
</s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); }, </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add
/** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, };
const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, }; /** * Shallow comparison between objects. If `keys` is provided, just that * subset of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.shallowCompareKeys(objA, objB, keys); }, };
[ "keep", "keep", "keep", "keep", "replace", "replace" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/common/utils.ts
import { Grid } from "../common"; import { Batcher } from "../common/batcher"; import { IFocusedCellCoordinates } from "../common/cell"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { IClientCoordinates, ICoordinateData } from "../interactions/draggable"; import { DragReorderable, IReorderableProps } from "../interactions/reorderable"; import { Resizable } from "../interactions/resizable"; import { ILockableLayout, Orientation } from "../interactions/resizeHandle"; import { DragSelectable, ISelectableProps } from "../interactions/selectable";
</s> remove import { Utils } from "./common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add
import { Grid } from "../common"; import { Batcher } from "../common/batcher"; import { IFocusedCellCoordinates } from "../common/cell"; import * as Classes from "../common/classes"; import { IClientCoordinates, ICoordinateData } from "../interactions/draggable"; import { DragReorderable, IReorderableProps } from "../interactions/reorderable"; import { Resizable } from "../interactions/resizable"; import { ILockableLayout, Orientation } from "../interactions/resizeHandle"; import { DragSelectable, ISelectableProps } from "../interactions/selectable";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/headers/header.tsx
} public shouldComponentUpdate(nextProps?: IInternalHeaderProps, nextState?: IHeaderState) { return ( !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) ); } public componentWillUpdate(nextProps?: IInternalHeaderProps, nextState?: IHeaderState) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST };
</s> remove let shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !Utils.shallowCompareKeys(this.state, nextState); </s> add let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState); </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !Utils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !Utils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !Utils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> remove return !Utils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> add return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist);
!CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST)
} public shouldComponentUpdate(nextProps?: IInternalHeaderProps, nextState?: IHeaderState) { return ( !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) ); } public componentWillUpdate(nextProps?: IInternalHeaderProps, nextState?: IHeaderState) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST };
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/headers/header.tsx
} public componentWillUpdate(nextProps?: IInternalHeaderProps, nextState?: IHeaderState) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST }; let shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !Utils.shallowCompareKeys(this.state, nextState); if (shouldResetBatcher) { this.batcher.reset(); } }
</s> remove const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> add const shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove return !Utils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> add return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !Utils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !Utils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !Utils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST)
let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState);
} public componentWillUpdate(nextProps?: IInternalHeaderProps, nextState?: IHeaderState) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST }; let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState); let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState); if (shouldResetBatcher) { this.batcher.reset(); } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/headers/header.tsx
import * as React from "react"; import { Classes as CoreClasses, ContextMenuTarget, IProps, Utils as CoreUtils } from "@blueprintjs/core"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { ResizeHandle } from "../interactions/resizeHandle"; export interface IHeaderCellProps extends IProps { /** * The index of the cell in the header. If provided, this will be passed as an argument to any
</s> remove import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; </s> add import { Classes as CoreClasses, IIntentProps, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add
import * as React from "react"; import { Classes as CoreClasses, ContextMenuTarget, IProps, Utils as CoreUtils } from "@blueprintjs/core"; import * as Classes from "../common/classes"; import { ResizeHandle } from "../interactions/resizeHandle"; export interface IHeaderCellProps extends IProps { /** * The index of the cell in the header. If provided, this will be passed as an argument to any
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/headers/headerCell.tsx
}; public shouldComponentUpdate(nextProps: IHeaderCellProps) { return ( !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) ); } public renderContextMenu(_event: React.MouseEvent<HTMLElement>) { const { renderMenu } = this.props;
</s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !Utils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !Utils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !Utils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> remove return !Utils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> add return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist);
!CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"])
}; public shouldComponentUpdate(nextProps: IHeaderCellProps) { return ( !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) ); } public renderContextMenu(_event: React.MouseEvent<HTMLElement>) { const { renderMenu } = this.props;
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/headers/headerCell.tsx
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps } from "@blueprintjs/core"; import * as PureRender from "pure-render-decorator"; import * as React from "react"; import * as ReactDOM from "react-dom"; import { Utils } from "../common/utils";
</s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add
import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; import * as PureRender from "pure-render-decorator"; import * as React from "react"; import * as ReactDOM from "react-dom"; import { Utils } from "../common/utils";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/draggable.tsx
import * as PureRender from "pure-render-decorator"; import * as React from "react"; import * as ReactDOM from "react-dom"; import { Utils } from "../common/utils"; import { DragEvents } from "./dragEvents"; export type IClientCoordinates = [number, number]; /**
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Keys } from "@blueprintjs/core"; </s> add import { Keys, Utils as CoreUtils } from "@blueprintjs/core";
import * as PureRender from "pure-render-decorator"; import * as React from "react"; import * as ReactDOM from "react-dom"; import { DragEvents } from "./dragEvents"; export type IClientCoordinates = [number, number]; /**
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/draggable.tsx
} public componentWillReceiveProps(nextProps: IDraggableProps) { const propsWhitelist = { include: REATTACH_PROPS_KEYS }; if (this.events && !Utils.shallowCompareKeys(this.props, nextProps, propsWhitelist)) { this.events.attach(ReactDOM.findDOMNode(this) as HTMLElement, nextProps); } } public componentDidMount() {
</s> remove return !Utils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> add return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> add const shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> remove !Utils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !Utils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !Utils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !Utils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"])
if (this.events && !CoreUtils.shallowCompareKeys(this.props, nextProps, propsWhitelist)) {
} public componentWillReceiveProps(nextProps: IDraggableProps) { const propsWhitelist = { include: REATTACH_PROPS_KEYS }; if (this.events && !CoreUtils.shallowCompareKeys(this.props, nextProps, propsWhitelist)) { this.events.attach(ReactDOM.findDOMNode(this) as HTMLElement, nextProps); } } public componentDidMount() {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/draggable.tsx
*/ import * as PureRender from "pure-render-decorator"; import * as React from "react"; import { IFocusedCellCoordinates } from "../common/cell"; import { Utils } from "../common/utils"; import { IRegion, RegionCardinality, Regions } from "../regions";
</s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Keys } from "@blueprintjs/core"; </s> add import { Keys, Utils as CoreUtils } from "@blueprintjs/core";
import { Utils as CoreUtils } from "@blueprintjs/core";
*/ import { Utils as CoreUtils } from "@blueprintjs/core"; import * as PureRender from "pure-render-decorator"; import * as React from "react"; import { IFocusedCellCoordinates } from "../common/cell"; import { Utils } from "../common/utils"; import { IRegion, RegionCardinality, Regions } from "../regions";
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/reorderable.tsx
private maybeSelectRegion(region: IRegion) { const nextSelectedRegions = [region]; if (!Utils.deepCompareKeys(nextSelectedRegions, this.props.selectedRegions)) { this.props.onSelection(nextSelectedRegions); // move the focused cell into the newly selected region this.props.onFocus({ ...Regions.getFocusCellCoordinatesFromRegion(region),
</s> remove BlueprintUtils.safeInvoke(this.props.onCompleteRender); </s> add CoreUtils.safeInvoke(this.props.onCompleteRender); </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> remove BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); </s> add CoreUtils.safeInvoke(this.props.onFocus, focusedCell); </s> remove BlueprintUtils.safeInvoke(onCopy, success); </s> add CoreUtils.safeInvoke(onCopy, success); </s> remove BlueprintUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> add CoreUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices);
if (!CoreUtils.deepCompareKeys(nextSelectedRegions, this.props.selectedRegions)) {
private maybeSelectRegion(region: IRegion) { const nextSelectedRegions = [region]; if (!CoreUtils.deepCompareKeys(nextSelectedRegions, this.props.selectedRegions)) { this.props.onSelection(nextSelectedRegions); // move the focused cell into the newly selected region this.props.onFocus({ ...Regions.getFocusCellCoordinatesFromRegion(region),
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/reorderable.tsx
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { Utils as BlueprintUtils } from "@blueprintjs/core"; import * as PureRender from "pure-render-decorator"; import * as React from "react"; import { IFocusedCellCoordinates } from "../common/cell"; import * as FocusedCellUtils from "../common/internal/focusedCellUtils"; import { Utils } from "../common/utils";
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
import { Utils as CoreUtils } from "@blueprintjs/core";
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { Utils as CoreUtils } from "@blueprintjs/core"; import * as PureRender from "pure-render-decorator"; import * as React from "react"; import { IFocusedCellCoordinates } from "../common/cell"; import * as FocusedCellUtils from "../common/internal/focusedCellUtils"; import { Utils } from "../common/utils";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/selectable.tsx
// mousemove; there's special handling for mousedown interactions that // target an already-selected region. if ( this.lastEmittedSelectedRegions == null || !Utils.deepCompareKeys(this.lastEmittedSelectedRegions, nextSelectedRegions) ) { onSelection(nextSelectedRegions); this.lastEmittedSelectedRegions = nextSelectedRegions; } }
</s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove !Utils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !Utils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, Utils.shallowCompareKeys) || !Utils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) </s> add !CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS })
!CoreUtils.deepCompareKeys(this.lastEmittedSelectedRegions, nextSelectedRegions)
// mousemove; there's special handling for mousedown interactions that // target an already-selected region. if ( this.lastEmittedSelectedRegions == null || !CoreUtils.deepCompareKeys(this.lastEmittedSelectedRegions, nextSelectedRegions) ) { onSelection(nextSelectedRegions); this.lastEmittedSelectedRegions = nextSelectedRegions; } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/selectable.tsx
// Other // ===== private finishInteraction = () => { BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); this.didExpandSelectionOnActivate = false; this.lastEmittedSelectedRegions = null; }; private expandSelectedRegions(regions: IRegion[], region: IRegion, focusedCell?: IFocusedCellCoordinates) {
</s> remove BlueprintUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> add CoreUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> remove BlueprintUtils.safeInvoke(this.props.onCompleteRender); </s> add CoreUtils.safeInvoke(this.props.onCompleteRender); </s> remove BlueprintUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> remove BlueprintUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> remove BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); </s> add CoreUtils.safeInvoke(this.props.onFocus, focusedCell);
CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions);
// Other // ===== private finishInteraction = () => { CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); this.didExpandSelectionOnActivate = false; this.lastEmittedSelectedRegions = null; }; private expandSelectedRegions(regions: IRegion[], region: IRegion, focusedCell?: IFocusedCellCoordinates) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/interactions/selectable.tsx
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils";
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core";
import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/layers/guides.tsx
import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; export interface IGuideLayerProps extends IProps { /** * The left-offset location of the vertical guides */
</s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Classes as CoreClasses, IIntentProps, IProps } from "@blueprintjs/core"; </s> add import { Classes as CoreClasses, IIntentProps, IProps, Utils as CoreUtils } from "@blueprintjs/core";
import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; export interface IGuideLayerProps extends IProps { /** * The left-offset location of the vertical guides */
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/layers/guides.tsx
} // shallow-comparing guide arrays leads to tons of unnecessary re-renders, so we check the // array contents explicitly. return ( !Utils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !Utils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) ); } public render() { const { verticalGuides, horizontalGuides, className } = this.props;
</s> remove !Utils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !Utils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, Utils.shallowCompareKeys) || !Utils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) </s> add !CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"])
!CoreUtils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !CoreUtils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides)
} // shallow-comparing guide arrays leads to tons of unnecessary re-renders, so we check the // array contents explicitly. return ( !CoreUtils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !CoreUtils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) !CoreUtils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !CoreUtils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) ); } public render() { const { verticalGuides, horizontalGuides, className } = this.props;
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/layers/guides.tsx
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { QuadrantType } from "../quadrants/tableQuadrant";
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { QuadrantType } from "../quadrants/tableQuadrant";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/layers/regions.tsx
import { IProps } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { Utils } from "../common/utils"; import { QuadrantType } from "../quadrants/tableQuadrant"; import { IRegion, Regions } from "../regions"; export type IRegionStyler = (region: IRegion, quadrantType?: QuadrantType) => React.CSSProperties;
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add
import { IProps } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; import { QuadrantType } from "../quadrants/tableQuadrant"; import { IRegion, Regions } from "../regions"; export type IRegionStyler = (region: IRegion, quadrantType?: QuadrantType) => React.CSSProperties;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/layers/regions.tsx
// shallowly comparable props like "className" tend not to change in the default table // implementation, so do that check last with hope that we return earlier and avoid it // altogether. return ( !Utils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !Utils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, Utils.shallowCompareKeys) || !Utils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) ); } public render() { return <div className={Classes.TABLE_OVERLAY_LAYER}>{this.renderRegionChildren()}</div>;
</s> remove !Utils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !Utils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) </s> add !CoreUtils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !CoreUtils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST)
!CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS })
// shallowly comparable props like "className" tend not to change in the default table // implementation, so do that check last with hope that we return earlier and avoid it // altogether. return ( !CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) !CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) !CoreUtils.arraysEqual(this.props.regions, nextProps.regions, Regions.regionsEqual) || !CoreUtils.arraysEqual(this.props.regionStyles, nextProps.regionStyles, CoreUtils.shallowCompareKeys) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { include: UPDATE_PROPS_KEYS }) ); } public render() { return <div className={Classes.TABLE_OVERLAY_LAYER}>{this.renderRegionChildren()}</div>;
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/layers/regions.tsx
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { AbstractComponent, IProps, Utils as BlueprintUtils } from "@blueprintjs/core"; import { Hotkey, Hotkeys, HotkeysTarget } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import { ICellProps } from "./cell/cell";
</s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core";
import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core";
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE * and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { AbstractComponent, IProps, Utils as CoreUtils } from "@blueprintjs/core"; import { Hotkey, Hotkeys, HotkeysTarget } from "@blueprintjs/core"; import * as classNames from "classnames"; import * as React from "react"; import { ICellProps } from "./cell/cell";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
const propKeysBlacklist = { exclude: Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }; const stateKeysBlacklist = { exclude: Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST }; return ( !Utils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !Utils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !Utils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !Utils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) ); } public componentWillReceiveProps(nextProps: ITableProps) { super.componentWillReceiveProps(nextProps);
</s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove let shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !Utils.shallowCompareKeys(this.state, nextState); </s> add let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState); </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props.style, nextProps.style) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props.style, nextProps.style)
!CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST)
const propKeysBlacklist = { exclude: Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }; const stateKeysBlacklist = { exclude: Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST }; return ( !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysBlacklist) || !CoreUtils.shallowCompareKeys(this.state, nextState, stateKeysBlacklist) || !CoreUtils.deepCompareKeys(this.props, nextProps, Table.SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) || !CoreUtils.deepCompareKeys(this.state, nextState, Table.SHALLOW_COMPARE_STATE_KEYS_BLACKLIST) ); } public componentWillReceiveProps(nextProps: ITableProps) { super.componentWillReceiveProps(nextProps);
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
const cells = Regions.enumerateUniqueCells(selectedRegions, grid.numRows, grid.numCols); const sparse = Regions.sparseMapCells(cells, getCellClipboardData); if (sparse != null) { const success = Clipboard.copyCells(sparse); BlueprintUtils.safeInvoke(onCopy, success); } }; private shouldDisableVerticalScroll() { const { fillBodyWithGhostCells } = this.props;
</s> remove BlueprintUtils.safeInvoke(this.props.onCompleteRender); </s> add CoreUtils.safeInvoke(this.props.onCompleteRender); </s> remove BlueprintUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> add CoreUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> remove BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); </s> add CoreUtils.safeInvoke(this.props.onFocus, focusedCell); </s> remove const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> add const shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add
CoreUtils.safeInvoke(onCopy, success);
const cells = Regions.enumerateUniqueCells(selectedRegions, grid.numRows, grid.numCols); const sparse = Regions.sparseMapCells(cells, getCellClipboardData); if (sparse != null) { const success = Clipboard.copyCells(sparse); CoreUtils.safeInvoke(onCopy, success); } }; private shouldDisableVerticalScroll() { const { fillBodyWithGhostCells } = this.props;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
// defined and the second after the viewportRect has been set. the cells // will only actually render once the viewportRect is defined though, so // we defer invoking onCompleteRender until that check passes. if (this.state.viewportRect != null) { BlueprintUtils.safeInvoke(this.props.onCompleteRender); } }; private handleFocusMoveLeft = (e: KeyboardEvent) => this.handleFocusMove(e, "left"); private handleFocusMoveLeftInternal = (e: KeyboardEvent) => this.handleFocusMoveInternal(e, "left");
</s> remove BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); </s> add CoreUtils.safeInvoke(this.props.onFocus, focusedCell); </s> remove BlueprintUtils.safeInvoke(onCopy, success); </s> add CoreUtils.safeInvoke(onCopy, success); </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove !Utils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !Utils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) </s> add !CoreUtils.arraysEqual(this.props.verticalGuides, nextProps.verticalGuides) || !CoreUtils.arraysEqual(this.props.horizontalGuides, nextProps.horizontalGuides) </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions);
CoreUtils.safeInvoke(this.props.onCompleteRender);
// defined and the second after the viewportRect has been set. the cells // will only actually render once the viewportRect is defined though, so // we defer invoking onCompleteRender until that check passes. if (this.state.viewportRect != null) { CoreUtils.safeInvoke(this.props.onCompleteRender); } }; private handleFocusMoveLeft = (e: KeyboardEvent) => this.handleFocusMove(e, "left"); private handleFocusMoveLeftInternal = (e: KeyboardEvent) => this.handleFocusMoveInternal(e, "left");
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
if (this.props.focusedCell == null) { this.setState({ focusedCell } as ITableState); } BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); }; private handleSelection = (selectedRegions: IRegion[]) => { // only set selectedRegions state if not specified in props if (this.props.selectedRegions == null) {
</s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove BlueprintUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> remove BlueprintUtils.safeInvoke(this.props.onCompleteRender); </s> add CoreUtils.safeInvoke(this.props.onCompleteRender); </s> remove BlueprintUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length);
CoreUtils.safeInvoke(this.props.onFocus, focusedCell);
if (this.props.focusedCell == null) { this.setState({ focusedCell } as ITableState); } CoreUtils.safeInvoke(this.props.onFocus, focusedCell); }; private handleSelection = (selectedRegions: IRegion[]) => { // only set selectedRegions state if not specified in props if (this.props.selectedRegions == null) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
}; private handleColumnsReordered = (oldIndex: number, newIndex: number, length: number) => { this.setState({ isReordering: false, verticalGuides: undefined } as ITableState); BlueprintUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); }; private handleRowsReordering = (horizontalGuides: number[]) => { this.setState({ isReordering: true, horizontalGuides } as ITableState); };
</s> remove BlueprintUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); </s> remove BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); </s> add CoreUtils.safeInvoke(this.props.onFocus, focusedCell); </s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */ </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> remove BlueprintUtils.safeInvoke(onCopy, success); </s> add CoreUtils.safeInvoke(onCopy, success);
CoreUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length);
}; private handleColumnsReordered = (oldIndex: number, newIndex: number, length: number) => { this.setState({ isReordering: false, verticalGuides: undefined } as ITableState); CoreUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); }; private handleRowsReordering = (horizontalGuides: number[]) => { this.setState({ isReordering: true, horizontalGuides } as ITableState); };
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
}; private handleRowsReordered = (oldIndex: number, newIndex: number, length: number) => { this.setState({ isReordering: false, horizontalGuides: undefined } as ITableState); BlueprintUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); }; private handleLayoutLock = (isLayoutLocked = false) => { this.setState({ isLayoutLocked }); };
</s> remove BlueprintUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> add CoreUtils.safeInvoke(this.props.onColumnsReordered, oldIndex, newIndex, length); </s> remove BlueprintUtils.safeInvoke(this.props.onFocus, focusedCell); </s> add CoreUtils.safeInvoke(this.props.onFocus, focusedCell); </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> remove /** Clamps the given number between min and max values. Returns value if within range, or closest bound. */ </s> add /** * Clamps the given number between min and max values. Returns value if within * range, or closest bound. */ </s> remove BlueprintUtils.safeInvoke(onCopy, success); </s> add CoreUtils.safeInvoke(onCopy, success);
CoreUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length);
}; private handleRowsReordered = (oldIndex: number, newIndex: number, length: number) => { this.setState({ isReordering: false, horizontalGuides: undefined } as ITableState); CoreUtils.safeInvoke(this.props.onRowsReordered, oldIndex, newIndex, length); }; private handleLayoutLock = (isLayoutLocked = false) => { this.setState({ isLayoutLocked }); };
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
private invokeOnVisibleCellsChangeCallback(viewportRect: Rect) { const columnIndices = this.grid.getColumnIndicesInRect(viewportRect); const rowIndices = this.grid.getRowIndicesInRect(viewportRect); BlueprintUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); } private getMaxFrozenColumnIndex = () => { const numFrozenColumns = this.getNumFrozenColumnsClamped(); return numFrozenColumns != null ? numFrozenColumns - 1 : undefined;
</s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove BlueprintUtils.safeInvoke(onCopy, success); </s> add CoreUtils.safeInvoke(onCopy, success); </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> remove describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); </s> add </s> remove function getCompareTestDescription(a?: any, b?: any, keys?: any) { const baseResult = `${JSON.stringify(a)} and ${JSON.stringify(b)}`; return keys != null ? baseResult + ` (keys: ${JSON.stringify(keys)})` : baseResult; } interface IKeys { a?: any; b?: any; c?: any; d?: any; } /** * A compactly named function for converting a string array to a key blacklist. */ function bl(keys: string[]) { return { exclude: keys } as IKeyBlacklist<IKeys>; } /** * A compactly named function for converting a string array to a key whitelist. */ function wl(keys: string[]) { return { include: keys } as IKeyWhitelist<IKeys>; } </s> add
CoreUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices);
private invokeOnVisibleCellsChangeCallback(viewportRect: Rect) { const columnIndices = this.grid.getColumnIndicesInRect(viewportRect); const rowIndices = this.grid.getRowIndicesInRect(viewportRect); CoreUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); } private getMaxFrozenColumnIndex = () => { const numFrozenColumns = this.getNumFrozenColumnsClamped(); return numFrozenColumns != null ? numFrozenColumns - 1 : undefined;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/table.tsx
import { ContextMenuTargetWrapper } from "./common/contextMenuTargetWrapper"; import { Grid, IColumnIndices, IRowIndices } from "./common/grid"; import { Rect } from "./common/rect"; import { RenderMode } from "./common/renderMode"; import { Utils } from "./common/utils"; import { ICoordinateData } from "./interactions/draggable"; import { IContextMenuRenderer, MenuContext } from "./interactions/menus"; import { DragSelectable, ISelectableProps } from "./interactions/selectable"; import { ILocator } from "./locator"; import { IRegion, Regions } from "./regions";
</s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption, Utils } from "../src"; </s> add import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption } from "../src"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils } from "../common/utils"; </s> add
import { ContextMenuTargetWrapper } from "./common/contextMenuTargetWrapper"; import { Grid, IColumnIndices, IRowIndices } from "./common/grid"; import { Rect } from "./common/rect"; import { RenderMode } from "./common/renderMode"; import { ICoordinateData } from "./interactions/draggable"; import { IContextMenuRenderer, MenuContext } from "./interactions/menus"; import { DragSelectable, ISelectableProps } from "./interactions/selectable"; import { ILocator } from "./locator"; import { IRegion, Regions } from "./regions";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/tableBody.tsx
} public shouldComponentUpdate(nextProps: ITableBodyProps) { const propKeysWhitelist = { include: UPDATE_PROPS_KEYS }; return !Utils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); } public componentWillUpdate(nextProps?: ITableBodyProps) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST }; const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist);
</s> remove const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> add const shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); </s> remove let shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !Utils.shallowCompareKeys(this.state, nextState); </s> add let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState); </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.shallowCompareKeys(this.state, nextState) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"])
return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist);
} public shouldComponentUpdate(nextProps: ITableBodyProps) { const propKeysWhitelist = { include: UPDATE_PROPS_KEYS }; return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); } public componentWillUpdate(nextProps?: ITableBodyProps) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST }; const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/tableBody.tsx
} public componentWillUpdate(nextProps?: ITableBodyProps) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST }; const shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); if (shouldResetBatcher) { this.batcher.reset(); } }
</s> remove let shouldResetBatcher = !Utils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !Utils.shallowCompareKeys(this.state, nextState); </s> add let shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); shouldResetBatcher = shouldResetBatcher || !CoreUtils.shallowCompareKeys(this.state, nextState); </s> remove return !Utils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> add return !CoreUtils.shallowCompareKeys(this.props, nextProps, propKeysWhitelist); </s> remove !Utils.shallowCompareKeys(this.state, nextState) || !Utils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !Utils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> add !CoreUtils.shallowCompareKeys(this.state, nextState) || !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: SHALLOW_COMPARE_PROP_KEYS_BLACKLIST }) || !CoreUtils.deepCompareKeys(this.props, nextProps, SHALLOW_COMPARE_PROP_KEYS_BLACKLIST) </s> remove !Utils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !Utils.deepCompareKeys(this.props, nextProps, ["style"]) </s> add !CoreUtils.shallowCompareKeys(this.props, nextProps, { exclude: ["style"] }) || !CoreUtils.deepCompareKeys(this.props, nextProps, ["style"]) </s> remove if (this.events && !Utils.shallowCompareKeys(this.props, nextProps, propsWhitelist)) { </s> add if (this.events && !CoreUtils.shallowCompareKeys(this.props, nextProps, propsWhitelist)) {
const shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist);
} public componentWillUpdate(nextProps?: ITableBodyProps) { const resetKeysBlacklist = { exclude: RESET_CELL_KEYS_BLACKLIST }; const shouldResetBatcher = !CoreUtils.shallowCompareKeys(this.props, nextProps, resetKeysBlacklist); if (shouldResetBatcher) { this.batcher.reset(); } }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/src/tableBody.tsx
import { mount, ReactWrapper, shallow } from "enzyme"; import * as React from "react"; import * as ReactDOM from "react-dom"; import { Keys } from "@blueprintjs/core"; import { dispatchMouseEvent } from "@blueprintjs/core/test/common/utils"; import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption, Utils } from "../src"; import { ICellCoordinates, IFocusedCellCoordinates } from "../src/common/cell"; import * as Classes from "../src/common/classes"; import * as Errors from "../src/common/errors";
</s> remove import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption, Utils } from "../src"; </s> add import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption } from "../src"; </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core";
import { Keys, Utils as CoreUtils } from "@blueprintjs/core";
import { mount, ReactWrapper, shallow } from "enzyme"; import * as React from "react"; import * as ReactDOM from "react-dom"; import { Keys, Utils as CoreUtils } from "@blueprintjs/core"; import { dispatchMouseEvent } from "@blueprintjs/core/test/common/utils"; import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption, Utils } from "../src"; import { ICellCoordinates, IFocusedCellCoordinates } from "../src/common/cell"; import * as Classes from "../src/common/classes"; import * as Errors from "../src/common/errors";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/test/tableTests.tsx
import * as ReactDOM from "react-dom"; import { Keys } from "@blueprintjs/core"; import { dispatchMouseEvent } from "@blueprintjs/core/test/common/utils"; import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption, Utils } from "../src"; import { ICellCoordinates, IFocusedCellCoordinates } from "../src/common/cell"; import * as Classes from "../src/common/classes"; import * as Errors from "../src/common/errors"; import { IColumnIndices, IRowIndices } from "../src/common/grid"; import { Rect } from "../src/common/rect";
</s> remove import { Keys } from "@blueprintjs/core"; </s> add import { Keys, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "./common/utils"; </s> add </s> remove import { IProps } from "@blueprintjs/core"; </s> add import { IProps, Utils as CoreUtils } from "@blueprintjs/core"; </s> remove import { Utils } from "../common/utils"; </s> add
import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption } from "../src";
import * as ReactDOM from "react-dom"; import { Keys } from "@blueprintjs/core"; import { dispatchMouseEvent } from "@blueprintjs/core/test/common/utils"; import { Cell, Column, ITableProps, RegionCardinality, Table, TableLoadingOption } from "../src"; import { ICellCoordinates, IFocusedCellCoordinates } from "../src/common/cell"; import * as Classes from "../src/common/classes"; import * as Errors from "../src/common/errors"; import { IColumnIndices, IRowIndices } from "../src/common/grid"; import { Rect } from "../src/common/rect";
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/test/tableTests.tsx
const expectedCols = sortInterval(ACTIVATION_CELL_COORDS.col, nextCellCoords.col); const expectedRows = sortInterval(ACTIVATION_CELL_COORDS.row, nextCellCoords.row); expect(Utils.arraysEqual(selectedCols, expectedCols)).to.be.true; expect(Utils.arraysEqual(selectedRows, expectedRows)).to.be.true; } function mountTable(rowHeight = ROW_HEIGHT, colWidth = COL_WIDTH) { // need to explicitly `.fill` a new array with empty values for mapping to work const defineColumn = (_unused: any, i: number) => <Column key={i} renderCell={renderCell} />;
</s> remove function getCompareTestDescription(a?: any, b?: any, keys?: any) { const baseResult = `${JSON.stringify(a)} and ${JSON.stringify(b)}`; return keys != null ? baseResult + ` (keys: ${JSON.stringify(keys)})` : baseResult; } interface IKeys { a?: any; b?: any; c?: any; d?: any; } /** * A compactly named function for converting a string array to a key blacklist. */ function bl(keys: string[]) { return { exclude: keys } as IKeyBlacklist<IKeys>; } /** * A compactly named function for converting a string array to a key whitelist. */ function wl(keys: string[]) { return { include: keys } as IKeyWhitelist<IKeys>; } </s> add </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); },
expect(CoreUtils.arraysEqual(selectedCols, expectedCols)).to.be.true; expect(CoreUtils.arraysEqual(selectedRows, expectedRows)).to.be.true;
const expectedCols = sortInterval(ACTIVATION_CELL_COORDS.col, nextCellCoords.col); const expectedRows = sortInterval(ACTIVATION_CELL_COORDS.row, nextCellCoords.row); expect(CoreUtils.arraysEqual(selectedCols, expectedCols)).to.be.true; expect(CoreUtils.arraysEqual(selectedRows, expectedRows)).to.be.true; expect(CoreUtils.arraysEqual(selectedCols, expectedCols)).to.be.true; expect(CoreUtils.arraysEqual(selectedRows, expectedRows)).to.be.true; } function mountTable(rowHeight = ROW_HEIGHT, colWidth = COL_WIDTH) { // need to explicitly `.fill` a new array with empty values for mapping to work const defineColumn = (_unused: any, i: number) => <Column key={i} renderCell={renderCell} />;
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/test/tableTests.tsx
* and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { expect } from "chai"; import { IKeyBlacklist, IKeyWhitelist, Utils } from "../src/common/utils"; describe("Utils", () => { describe("toBase26Alpha", () => { it("converts to spreadsheet-like base26", () => { expect(Utils.toBase26Alpha(0)).to.equal("A");
</s> remove import { Utils } from "../../src"; </s> add import * as Utils from "../../src/common/utils"; </s> remove describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); </s> add </s> remove BlueprintUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> add CoreUtils.safeInvoke(this.props.onVisibleCellsChange, rowIndices, columnIndices); </s> remove BlueprintUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> add CoreUtils.safeInvoke(this.props.onSelectionEnd, this.props.selectedRegions); </s> remove import { Utils as BlueprintUtils } from "@blueprintjs/core"; </s> add import { Utils as CoreUtils } from "@blueprintjs/core";
import { Utils } from "../src/common/utils";
* and https://github.com/palantir/blueprint/blob/master/PATENTS */ import { expect } from "chai"; import { Utils } from "../src/common/utils"; describe("Utils", () => { describe("toBase26Alpha", () => { it("converts to spreadsheet-like base26", () => { expect(Utils.toBase26Alpha(0)).to.equal("A");
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/test/utilsTests.ts
// use .eql to deeply compare arrays expect(result).to.eql(expected.split("")); } }); describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); }); function getCompareTestDescription(a?: any, b?: any, keys?: any) { const baseResult = `${JSON.stringify(a)} and ${JSON.stringify(b)}`; return keys != null ? baseResult + ` (keys: ${JSON.stringify(keys)})` : baseResult;
</s> remove arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any) => a === b) { // treat `null` and `undefined` as the same if (arrA == null && arrB == null) { return true; } else if (arrA == null || arrB == null || arrA.length !== arrB.length) { return false; } else { return arrA.every((a, i) => compare(a, arrB[i])); } }, }; </s> add arraysEqual: CoreUtils.arraysEqual, </s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove function getCompareTestDescription(a?: any, b?: any, keys?: any) { const baseResult = `${JSON.stringify(a)} and ${JSON.stringify(b)}`; return keys != null ? baseResult + ` (keys: ${JSON.stringify(keys)})` : baseResult; } interface IKeys { a?: any; b?: any; c?: any; d?: any; } /** * A compactly named function for converting a string array to a key blacklist. */ function bl(keys: string[]) { return { exclude: keys } as IKeyBlacklist<IKeys>; } /** * A compactly named function for converting a string array to a key whitelist. */ function wl(keys: string[]) { return { include: keys } as IKeyWhitelist<IKeys>; } </s> add </s> remove * Returns true if the arrays are equal. Elements will be shallowly compared by default, or they * will be compared using the custom `compare` function if one is provided. </s> add * Returns true if the arrays are equal. Elements will be shallowly compared * by default, or they will be compared using the custom `compare` function * if one is provided. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add
// use .eql to deeply compare arrays expect(result).to.eql(expected.split("")); } }); }); function getCompareTestDescription(a?: any, b?: any, keys?: any) { const baseResult = `${JSON.stringify(a)} and ${JSON.stringify(b)}`; return keys != null ? baseResult + ` (keys: ${JSON.stringify(keys)})` : baseResult;
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/test/utilsTests.ts
}); } }); }); function getCompareTestDescription(a?: any, b?: any, keys?: any) { const baseResult = `${JSON.stringify(a)} and ${JSON.stringify(b)}`; return keys != null ? baseResult + ` (keys: ${JSON.stringify(keys)})` : baseResult; } interface IKeys { a?: any; b?: any; c?: any; d?: any; } /** * A compactly named function for converting a string array to a key blacklist. */ function bl(keys: string[]) { return { exclude: keys } as IKeyBlacklist<IKeys>; } /** * A compactly named function for converting a string array to a key whitelist. */ function wl(keys: string[]) { return { include: keys } as IKeyWhitelist<IKeys>; }
</s> remove /** * Partial shallow comparison between objects using the given list of keys. */ function _shallowCompareKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { return _filterKeys(objA, objB, keys).every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && objA[key] === objB[key]; }); } /** * Partial deep comparison between objects using the given list of keys. */ function _deepCompareKeys(objA: any, objB: any, keys: string[]): boolean { return keys.every(key => { return objA.hasOwnProperty(key) === objB.hasOwnProperty(key) && Utils.deepCompareKeys(objA[key], objB[key]); }); } function _isSimplePrimitiveType(value: any) { return typeof value === "number" || typeof value === "string" || typeof value === "boolean"; } function _filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<T>) { if (isWhitelist(keys)) { return keys.include; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); // merge keys from both objects into a big set for quick access const keySet = _arrayToObject(keysA.concat(keysB)); // delete blacklisted keys from the key set keys.exclude.forEach(key => delete keySet[key]); // return the remaining keys as an array return Object.keys(keySet) as Array<keyof T>; } } function isWhitelist<T>(keys: any): keys is IKeyWhitelist<T> { return keys != null && (keys as IKeyWhitelist<T>).include != null; } function _arrayToObject(arr: any[]) { return arr.reduce((obj: any, element: any) => { obj[element] = true; return obj; }, {}); } function _getUnequalKeyValues<T extends object>( objA: T, objB: T, keys: Array<keyof T>, compareFn: (objA: any, objB: any, key: keyof T) => boolean, ) { const unequalKeys = keys.filter(key => !compareFn(objA, objB, key)); const unequalKeyValues = unequalKeys.map(key => ({ key, valueA: objA[key], valueB: objB[key], })); return unequalKeyValues; } </s> add /** * Deep comparison between objects. If `keys` is provided, just that subset * of keys will be compared; otherwise, all keys will be compared. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ deepCompareKeys: CoreUtils.deepCompareKeys, </s> remove /** * Shallow comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ shallowCompareKeys<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // treat `null` and `undefined` as the same if (objA == null && objB == null) { return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return false; } else if (keys != null) { return _shallowCompareKeys(objA, objB, keys); } else { // shallowly compare all keys from both objects const keysA = Object.keys(objA) as Array<keyof T>; const keysB = Object.keys(objB) as Array<keyof T>; return ( _shallowCompareKeys(objA, objB, { include: keysA }) && _shallowCompareKeys(objA, objB, { include: keysB }) ); } }, /** * Deep comparison between objects. If `keys` is provided, just that subset of keys will be * compared; otherwise, all keys will be compared. */ deepCompareKeys(objA: any, objB: any, keys?: string[]): boolean { if (objA === objB) { return true; } else if (objA == null && objB == null) { // treat `null` and `undefined` as the same return true; } else if (objA == null || objB == null) { return false; } else if (Array.isArray(objA) || Array.isArray(objB)) { return Utils.arraysEqual(objA, objB, Utils.deepCompareKeys); } else if (_isSimplePrimitiveType(objA) || _isSimplePrimitiveType(objB)) { return objA === objB; } else if (keys != null) { return _deepCompareKeys(objA, objB, keys); } else if (objA.constructor !== objB.constructor) { return false; } else { const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA == null || keysB == null) { return false; } if (keysA.length === 0 && keysB.length === 0) { return true; } return Utils.arraysEqual(keysA, keysB) && _deepCompareKeys(objA, objB, keysA); } }, /** * Returns a descriptive object for each key whose values are shallowly unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { // default param values let null values pass through, so we have to take this more thorough approach const definedObjA = objA == null ? {} : objA; const definedObjB = objB == null ? {} : objB; const filteredKeys = _filterKeys(definedObjA, definedObjB, keys == null ? { exclude: [] } : keys); return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.shallowCompareKeys(a, b, { include: [key] }), ); }, /** * Returns a descriptive object for each key whose values are deeply unequal between two * provided objects. Useful for debugging shouldComponentUpdate. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { const definedObjA = objA == null ? {} as T : objA; const definedObjB = objB == null ? {} as T : objB; const filteredKeys = keys == null ? _unionKeys(definedObjA, definedObjB) : keys; return _getUnequalKeyValues(definedObjA, definedObjB, filteredKeys, (a, b, key) => Utils.deepCompareKeys(a, b, [key]), ); }, </s> add </s> remove describe("shallowCompareKeys", () => { describe("with `keys` defined as whitelist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, wl(["a", "b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, wl(["a", "b", "c"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, wl(["a", "b"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, wl([])); runTest(true, undefined, undefined, wl(["a"])); runTest(true, null, null, wl(["a"])); runTest(true, {}, {}, wl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, wl([])); runTest(false, {}, [], wl([])); runTest(false, [], [], wl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` defined as blacklist", () => { describe("returns true if only the specified values are shallowly equal", () => { runTest(true, { a: 1 }, { a: 1 }, bl(["b", "c", "d"])); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["c"])); }); describe("returns false if any specified values are not shallowly equal", () => { runTest(false, { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b, c"])); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, bl(["a", "b", "d"])); runTest(false, { a: 1, c: { a: 1 } }, { a: 1, b: "2" }, bl(["c"])); }); describe("edge cases that return true", () => { runTest(true, undefined, null, bl([])); runTest(true, undefined, undefined, bl(["a"])); runTest(true, null, null, bl(["a"])); runTest(true, {}, {}, bl(["a"])); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, bl([])); runTest(false, {}, [], bl([])); runTest(false, [], [], bl([])); }); function runTest( expectedResult: boolean, a: any, b: any, keys: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>, ) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are shallowly equal", () => { runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not shallowly equal", () => { runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.shallowCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("deepCompareKeys", () => { // tslint:disable:max-classes-per-file class DVD { public constructor() { /* Empty */ } } class VHSTape { public constructor() { /* Empty */ } } // tslint:enable:max-classes-per-file describe("with `keys` defined", () => { describe("returns true if only the specified values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1 }, { a: 1 }, ["a", "b", "c", "d"]); runTest(true, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(true, { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); runTest(true, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 1 } }, ["b", "c"]); }); describe("returns false if any specified values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, { a: [1, "2", true] }, { a: [1, "2", false] }, ["a"]); runTest(false, { a: customInstance1 }, { a: customInstance2 }, ["a"]); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: 2 } }, ["a", "b", "c"]); }); describe("edge cases that return true", () => { runTest(true, undefined, null, []); runTest(true, undefined, undefined, ["a"]); runTest(true, null, null, ["a"]); runTest(true, {}, {}, ["a"]); }); describe("edge cases that return false", () => { runTest(false, {}, undefined, []); runTest(false, {}, [], []); }); function runTest(expectedResult: boolean, a: any, b: any, keys: string[]) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b, keys)).to.equal(expectedResult); }); } }); describe("with `keys` not defined", () => { describe("returns true if values are deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new DVD(); runTest(true, { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest(true, { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); runTest(true, [1, "2", true], [1, "2", true]); runTest(true, 1, 1); runTest(true, customInstance1, customInstance2); runTest(true, "2", "2"); runTest(true, undefined, undefined); runTest(true, null, undefined); }); describe("returns false if values are not deeply equal", () => { const customInstance1 = new DVD(); const customInstance2 = new VHSTape(); runTest(false, undefined, {}); runTest(false, null, {}); runTest(false, {}, []); runTest(false, { a: 1, b: "2", c: { a: 1 } }, { a: 1, b: "2", c: { a: "1" } }); runTest(false, customInstance1, customInstance2); }); describe("returns false if keys are different", () => { runTest(false, {}, { a: 1 }); runTest(false, { a: 1, b: "2" }, { b: "2" }); runTest(false, { a: 1, b: "2", c: true }, { b: "2", c: true, d: 3 }); }); describe("returns true if same deeply-comparable instance is reused in both objects", () => { const deeplyComparableThing1 = { a: 1 }; const deeplyComparableThing2 = [1, "2", true]; runTest(true, { a: 1, b: deeplyComparableThing1 }, { a: 1, b: deeplyComparableThing1 }); runTest(true, { a: 1, b: deeplyComparableThing2 }, { a: 1, b: deeplyComparableThing2 }); }); function runTest(expectedResult: boolean, a: any, b: any) { it(getCompareTestDescription(a, b), () => { expect(Utils.deepCompareKeys(a, b)).to.equal(expectedResult); }); } }); }); describe("getShallowUnequalKeyValues", () => { describe("with `keys` defined as whitelist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, wl(["a", "c"])); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { // identical objects, but different instances runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, wl(["a"]), ); // different primitive-type values runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, wl(["a"])); }); }); describe("with `keys` defined as blacklist", () => { describe("returns empty array if the specified values are shallowly equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, bl(["b"])); }); describe("returns unequal keys/values if any specified values are not shallowly equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", true] }], { a: [1, "2", true] }, { a: [1, "2", true] }, bl(["b", "c"]), ); runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }, bl(["b"])); }); }); describe("with `keys` not defined", () => { describe("returns empty array if values are shallowly equal", () => { runTest([], { a: 1, b: "2", c: true }, { a: 1, b: "2", c: true }); runTest([], undefined, undefined); runTest([], null, undefined); }); describe("returns unequal key/values if any specified values are not shallowly equal", () => { runTest([{ key: "a", valueA: 1, valueB: 2 }], { a: 1 }, { a: 2 }); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: IKeyBlacklist<IKeys> | IKeyWhitelist<IKeys>) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getShallowUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("getDeepUnequalKeyValues", () => { describe("with `keys` defined", () => { describe("returns empty array if only the specified values are deeply equal", () => { runTest([], { a: 1, b: [1, 2, 3], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["b", "c"]); }); describe("returns unequal key/values if any specified values are not deeply equal", () => { runTest( [{ key: "a", valueA: 2, valueB: 1 }, { key: "b", valueA: [2, 3, 4], valueB: [1, 2, 3] }], { a: 2, b: [2, 3, 4], c: "3" }, { b: [1, 2, 3], a: 1, c: "3" }, ["a", "b"], ); }); }); describe("with `keys` not defined", () => { describe("returns empty arrau if values are deeply equal", () => { runTest([], { a: 1, b: "2", c: { a: 1, b: "2" } }, { a: 1, b: "2", c: { a: 1, b: "2" } }); }); describe("returns unequal key/values if values are not deeply equal", () => { runTest( [{ key: "a", valueA: [1, "2", true], valueB: [1, "2", false] }], { a: [1, "2", true] }, { a: [1, "2", false] }, ); }); }); function runTest(expectedResult: any[], a: any, b: any, keys?: string[]) { it(getCompareTestDescription(a, b, keys), () => { expect(Utils.getDeepUnequalKeyValues(a, b, keys)).to.deep.equal(expectedResult); }); } }); describe("arraysEqual", () => { describe("no compare function provided", () => { describe("should return true if the arrays are shallowly equal", () => { runTest(true, undefined, undefined); runTest(true, undefined, null); runTest(true, [3, "1", true], [3, "1", true]); }); describe("should return false if the arrays are not shallowly equal", () => { runTest(false, null, [3]); runTest(false, [3, 1, 2], [3, 1]); runTest(false, [{ x: 1 }], [{ x: 1 }]); }); }); describe("compare function provided", () => { const COMPARE_FN = (a: any, b: any) => a.x === b.x; describe("should return true if the arrays are equal using a custom compare function", () => { runTest(true, undefined, undefined, COMPARE_FN); runTest(true, undefined, null, COMPARE_FN); runTest(true, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); describe("should return false if the arrays are not equal using custom compare function", () => { runTest(false, null, [], COMPARE_FN); runTest(false, [{ x: 1 }, {}], [{ x: 1 }, { x: 2 }], COMPARE_FN); }); }); function runTest(expectedResult: boolean, a: any, b: any, compareFn?: (a: any, b: any) => boolean) { it(getCompareTestDescription(a, b), () => { expect(Utils.arraysEqual(a, b, compareFn)).to.equal(expectedResult); }); } }); </s> add </s> remove const concatKeys = keysA.concat(keysB); const keySet = _arrayToObject(concatKeys); </s> add /** * Returns a descriptive object for each key whose values are shallowly * unequal between two provided objects. Useful for debugging * shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getShallowUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: IKeyBlacklist<T> | IKeyWhitelist<T>) { return CoreUtils.getShallowUnequalKeyValues(objA, objB, keys); }, </s> remove function _unionKeys<T extends object>(objA: T, objB: T) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); </s> add /** * Returns a descriptive object for each key whose values are deeply unequal * between two provided objects. Useful for debugging shouldComponentUpdate. * @deprecated since @blueprintjs/table 1.26.0; import this function from * core Utils instead. */ getDeepUnequalKeyValues<T extends object>(objA: T, objB: T, keys?: Array<keyof T>) { return CoreUtils.getDeepUnequalKeyValues(objA, objB, keys); },
}); } }); });
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace" ]
[Table/Core] Move some table utils into core (#1604) * Move util functions into core * Reorganize core Utils file * Adjust comment line length * Move tests into core * Change references to CoreUtils throughout table package * Add facades in table Utils to not break everybody * Fix build * Move code into utils/compareUtils.ts
https://github.com/palantir/blueprint/commit/ae1524cf26a4b304bb872b1a275139d05f326d75
packages/table/test/utilsTests.ts
]; const SLOW_LAYOUT_STACK_DEPTH = 120; const COLUMN_COUNT_DEFAULT_INDEX = 3; const ROW_COUNT_DEFAULT_INDEX = 4;
</s> remove truncateLength={80} </s> add truncateLength={this.state.cellTruncationLength}
const TRUNCATION_LENGTHS: number[] = [20, 80, 100, 1000]; const TRUNCATION_LENGTH_DEFAULT_INDEX = 1;
]; const TRUNCATION_LENGTHS: number[] = [20, 80, 100, 1000]; const TRUNCATION_LENGTH_DEFAULT_INDEX = 1; const SLOW_LAYOUT_STACK_DEPTH = 120; const COLUMN_COUNT_DEFAULT_INDEX = 3; const ROW_COUNT_DEFAULT_INDEX = 4;
[ "keep", "add", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
cellContent?: CellContent; cellTruncatedPopoverMode?: TruncatedPopoverMode; enableBatchRendering?: boolean; enableCellEditing?: boolean; enableCellSelection?: boolean; enableCellTruncation?: boolean;
</s> remove truncateLength={80} </s> add truncateLength={this.state.cellTruncationLength}
cellTruncationLength?: number;
cellContent?: CellContent; cellTruncatedPopoverMode?: TruncatedPopoverMode; cellTruncationLength?: number; enableBatchRendering?: boolean; enableCellEditing?: boolean; enableCellSelection?: boolean; enableCellTruncation?: boolean;
[ "keep", "add", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
enableCellEditing?: boolean; enableCellSelection?: boolean; enableCellTruncation?: boolean; enableCellWrap?: boolean; enableColumnCustomHeaders?: boolean; enableColumnNameEditing?: boolean; enableColumnReordering?: boolean;
</s> remove truncateLength={80} </s> add truncateLength={this.state.cellTruncationLength}
enableCellTruncationFixed?: boolean;
enableCellEditing?: boolean; enableCellSelection?: boolean; enableCellTruncation?: boolean; enableCellTruncationFixed?: boolean; enableCellWrap?: boolean; enableColumnCustomHeaders?: boolean; enableColumnNameEditing?: boolean; enableColumnReordering?: boolean;
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
const DEFAULT_STATE: IMutableTableState = { cellContent: CellContent.LONG_TEXT, cellTruncatedPopoverMode: TruncatedPopoverMode.WHEN_TRUNCATED, enableBatchRendering: true, enableCellEditing: false, enableCellSelection: true, enableCellTruncation: false, enableCellTruncationFixed: false,
</s> remove detectTruncation={true} </s> add detectTruncation={!this.state.enableCellTruncationFixed}
cellTruncationLength: TRUNCATION_LENGTHS[TRUNCATION_LENGTH_DEFAULT_INDEX],
const DEFAULT_STATE: IMutableTableState = { cellContent: CellContent.LONG_TEXT, cellTruncatedPopoverMode: TruncatedPopoverMode.WHEN_TRUNCATED, cellTruncationLength: TRUNCATION_LENGTHS[TRUNCATION_LENGTH_DEFAULT_INDEX], enableBatchRendering: true, enableCellEditing: false, enableCellSelection: true, enableCellTruncation: false, enableCellTruncationFixed: false,
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
enableCellSelection: true, enableCellTruncation: false, enableCellWrap: false, enableColumnCustomHeaders: true, enableColumnNameEditing: false, enableColumnReordering: true, enableColumnResizing: true, enableColumnSelection: true,
</s> remove truncateLength={80} </s> add truncateLength={this.state.cellTruncationLength}
enableCellTruncationFixed: false,
enableCellSelection: true, enableCellTruncation: false, enableCellTruncationFixed: false, enableCellWrap: false, enableColumnCustomHeaders: true, enableColumnNameEditing: false, enableColumnReordering: true, enableColumnResizing: true, enableColumnSelection: true,
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
} else if (this.state.enableCellTruncation) { return ( <Cell className={classes} wrapText={this.state.enableCellWrap}> <TruncatedFormat detectTruncation={true} preformatted={false} showPopover={this.state.cellTruncatedPopoverMode} truncateLength={80} truncationSuffix="..." >
</s> remove truncateLength={80} </s> add truncateLength={this.state.cellTruncationLength}
detectTruncation={!this.state.enableCellTruncationFixed}
} else if (this.state.enableCellTruncation) { return ( <Cell className={classes} wrapText={this.state.enableCellWrap}> <TruncatedFormat detectTruncation={!this.state.enableCellTruncationFixed} preformatted={false} showPopover={this.state.cellTruncatedPopoverMode} truncateLength={80} truncationSuffix="..." >
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
<TruncatedFormat detectTruncation={true} preformatted={false} showPopover={this.state.cellTruncatedPopoverMode} truncateLength={80} truncationSuffix="..." > {valueAsString} </TruncatedFormat> </Cell>
</s> remove detectTruncation={true} </s> add detectTruncation={!this.state.enableCellTruncationFixed}
truncateLength={this.state.cellTruncationLength}
<TruncatedFormat detectTruncation={true} preformatted={false} showPopover={this.state.cellTruncatedPopoverMode} truncateLength={this.state.cellTruncationLength} truncationSuffix="..." > {valueAsString} </TruncatedFormat> </Cell>
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx
true, ); return ( <div className="sidebar pt-elevation-0"> <h4>Table</h4>
</s> remove detectTruncation={true} </s> add detectTruncation={!this.state.enableCellTruncationFixed}
const truncatedLengthMenu = this.renderSelectMenu( "Length", "cellTruncationLength", TRUNCATION_LENGTHS, this.toValueLabel, this.handleNumberStateChange, "enableCellTruncationFixed", true, );
true, ); const truncatedLengthMenu = this.renderSelectMenu( "Length", "cellTruncationLength", TRUNCATION_LENGTHS, this.toValueLabel, this.handleNumberStateChange, "enableCellTruncationFixed", true, ); return ( <div className="sidebar pt-elevation-0"> <h4>Table</h4>
[ "keep", "add", "keep", "keep", "keep", "keep" ]
[Table] Add more switches for text layout to dev preview (#1641) * add switches for truncating to string length * lint
https://github.com/palantir/blueprint/commit/ae5974d733eda58ecd47a483fb7b77dcbbea13a7
packages/table/preview/mutableTable.tsx