Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pydeck-carto): Use local isPureObject #8880

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
Loading