Skip to content

Commit

Permalink
CJS Fix: Remove shallowequal dependency (#1407)
Browse files Browse the repository at this point in the history
* fix: remove shallowequal dependency

* fix: remove some invariant uses
  • Loading branch information
darthtrevino committed Jun 18, 2019
1 parent 5036db0 commit d300c1e
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 21 deletions.
3 changes: 1 addition & 2 deletions packages/core/react-dnd/package.json
Expand Up @@ -19,8 +19,7 @@
"dependencies": {
"@types/hoist-non-react-statics": "^3.3.1",
"dnd-core": "^8.0.1",
"hoist-non-react-statics": "^3.3.0",
"shallowequal": "^1.1.0"
"hoist-non-react-statics": "^3.3.0"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
Expand Down
3 changes: 1 addition & 2 deletions packages/core/react-dnd/src/common/SourceConnector.ts
Expand Up @@ -3,8 +3,7 @@ import wrapConnectorHooks from './wrapConnectorHooks'
import { Backend, Unsubscribe, Identifier } from 'dnd-core'
import { isRef } from '../utils/isRef'
import { DragSourceOptions, DragPreviewOptions } from '../interfaces'
// @ts-ignore
import shallowEqual from 'shallowequal'
import shallowEqual from '../utils/shallowEqual'

export interface Connector {
hooks: any
Expand Down
3 changes: 1 addition & 2 deletions packages/core/react-dnd/src/common/TargetConnector.ts
Expand Up @@ -2,8 +2,7 @@ import * as React from 'react'
import wrapConnectorHooks from './wrapConnectorHooks'
import { Backend, Unsubscribe, Identifier } from 'dnd-core'
import { isRef } from '../utils/isRef'
// @ts-ignore
import shallowEqual from 'shallowequal'
import shallowEqual from '../utils/shallowEqual'

import { Connector } from './SourceConnector'

Expand Down
3 changes: 1 addition & 2 deletions packages/core/react-dnd/src/decorators/DragDropContext.tsx
Expand Up @@ -3,8 +3,7 @@ import { DndContext, createDndContext } from '../common/DndContext'
import { BackendFactory } from 'dnd-core'
import { checkDecoratorArguments, isRefable } from './utils'
import { ContextComponent } from './interfaces'
// @ts-ignore
import invariant from 'invariant'
import invariant from '../utils/invariant'
// @ts-ignore
import hoistStatics from 'hoist-non-react-statics'

Expand Down
6 changes: 2 additions & 4 deletions packages/core/react-dnd/src/decorators/DragLayer.tsx
Expand Up @@ -7,10 +7,8 @@ import { isRefable, checkDecoratorArguments } from './utils'

// @ts-ignore
import hoistStatics from 'hoist-non-react-statics'
// @ts-ignore
import invariant from 'invariant'
// @ts-ignore
import shallowEqual from 'shallowequal'
import invariant from '../utils/invariant'
import shallowEqual from '../utils/shallowEqual'

export function DragLayer<RequiredProps, CollectedProps = {}>(
collect: DragLayerCollector<RequiredProps, CollectedProps>,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/react-dnd/src/decorators/createSourceFactory.ts
Expand Up @@ -5,8 +5,6 @@ import { DragSourceMonitor } from '../interfaces'
import { isPlainObject } from '../utils/discount_lodash'
import { DragSourceSpec } from './interfaces'
import { getDecoratedComponent } from './utils'

// @ts-ignore
import invariant from '../utils/invariant'

const ALLOWED_SPEC_METHODS = ['canDrag', 'beginDrag', 'isDragging', 'endDrag']
Expand Down
6 changes: 2 additions & 4 deletions packages/core/react-dnd/src/decorators/decorateHandler.tsx
Expand Up @@ -12,12 +12,10 @@ import {
SerialDisposable,
} from './disposables'
import { isRefable } from './utils'
// @ts-ignore
import invariant from 'invariant'
import invariant from '../utils/invariant'
// @ts-ignore
import hoistStatics from 'hoist-non-react-statics'
// @ts-ignore
import shallowEqual from 'shallowequal'
import shallowEqual from '../utils/shallowEqual'

export interface DecorateHandlerArgs<Props, ItemIdType> {
DecoratedComponent: any
Expand Down
3 changes: 1 addition & 2 deletions packages/core/react-dnd/src/hooks/internal/useCollector.ts
@@ -1,5 +1,4 @@
// @ts-ignore
import shallowEqual from 'shallowequal'
import shallowEqual from '../../utils/shallowEqual'
import { useState, useCallback } from 'react'

/**
Expand Down
51 changes: 51 additions & 0 deletions packages/core/react-dnd/src/utils/shallowEqual.ts
@@ -0,0 +1,51 @@
// taken from https://github.com/dashed/shallowequal/

export default function shallowEqual(
objA: any,
objB: any,
compare?: any,
compareContext?: any,
) {
var ret = compare ? compare.call(compareContext, objA, objB) : void 0

if (ret !== void 0) {
return !!ret
}

if (objA === objB) {
return true
}

if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
return false
}

var keysA = Object.keys(objA)
var keysB = Object.keys(objB)

if (keysA.length !== keysB.length) {
return false
}

var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB)

// Test for A's keys different from B.
for (var idx = 0; idx < keysA.length; idx++) {
var key = keysA[idx]

if (!bHasOwnProperty(key)) {
return false
}

var valueA = objA[key]
var valueB = objB[key]

ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0

if (ret === false || (ret === void 0 && valueA !== valueB)) {
return false
}
}

return true
}
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -14526,7 +14526,7 @@ shallow-compare@^1.2.2:
resolved "https://registry.yarnpkg.com/shallow-compare/-/shallow-compare-1.2.2.tgz#fa4794627bf455a47c4f56881d8a6132d581ffdb"
integrity sha512-LUMFi+RppPlrHzbqmFnINTrazo0lPNwhcgzuAXVVcfy/mqPDrQmHAyz5bvV0gDAuRFrk804V0HpQ6u9sZ0tBeg==

shallowequal@^1.0.1, shallowequal@^1.0.2, shallowequal@^1.1.0:
shallowequal@^1.0.1, shallowequal@^1.0.2:
version "1.1.0"
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==
Expand Down

0 comments on commit d300c1e

Please sign in to comment.