Skip to content

Commit

Permalink
fix(pydeck-carto): Use local isPureObject (#8880)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored May 10, 2024
1 parent 950d666 commit 5270e55
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/carto/src/api/request-with-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isPureObject} from '@loaders.gl/core';
import {isPureObject} from '../utils';
import {CartoAPIError} from './carto-api-error';
import {DEFAULT_HEADERS, DEFAULT_PARAMETERS, MAX_GET_LENGTH} from './common';
import type {APIErrorContext} from './types';
Expand Down
5 changes: 5 additions & 0 deletions modules/carto/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ export function scaleIdentity() {

return scale;
}

export const isObject: (x: unknown) => boolean = x => x !== null && typeof x === 'object';

export const isPureObject: (x: any) => boolean = x =>
isObject(x) && x.constructor === {}.constructor;
26 changes: 25 additions & 1 deletion test/modules/carto/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import test from 'tape-promise/tape';
import {createBinaryProxy, getWorkerUrl, scaleIdentity} from '@deck.gl/carto/utils';
import {
createBinaryProxy,
getWorkerUrl,
scaleIdentity,
isObject,
isPureObject
} from '@deck.gl/carto/utils';

test('createBinaryProxy', async t => {
const binary = {
Expand Down Expand Up @@ -54,3 +60,21 @@ test('scaleIdentity', async t => {

t.end();
});

test('isObject', t => {
class TestClass {}
t.equal(isObject({}), true, 'object is object');
t.equal(isObject(3), false, 'number is not object');
t.equal(isObject([]), true, 'array is object');
t.equal(isObject(new TestClass()), true, 'class instance is object');
t.end();
});

test('isPureObject', t => {
class TestClass {}
t.equal(isPureObject({}), true, 'object is pure');
t.equal(isPureObject(3), false, 'number is not pure');
t.equal(isPureObject([]), false, 'array is not pure');
t.equal(isPureObject(new TestClass()), false, 'class instance is not pure');
t.end();
});

0 comments on commit 5270e55

Please sign in to comment.