Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: remove lodash from dnd-core * chore: remove lodash from html5 backend * chore: remove lodash from test backend * chore: remove lodash from react-dnd * docs: update FAQ info about using function components * chore: rebuild yarn lock * chore: upgrade tslint-react
- Loading branch information
1 parent
d2133ea
commit 0a54e41
Showing
28 changed files
with
1,386 additions
and
1,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { xor, intersection } from '../discount_lodash' | ||
|
||
describe('the utilities module', () => { | ||
it('can compute xor', () => { | ||
const result = xor([1, 5, 7], [1, 3, 9, 7]) | ||
expect(result).toEqual([5, 3, 9]) | ||
}) | ||
|
||
it('can compute intersection', () => { | ||
const result = intersection([1, 5, 7], [1, 3, 9, 7]) | ||
expect(result).toEqual([1, 7]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* drop-in replacement for _.get | ||
* @param obj | ||
* @param path | ||
* @param defaultValue | ||
*/ | ||
export function get<T>(obj: any, path: string, defaultValue: T): T { | ||
return path | ||
.split('.') | ||
.reduce((a, c) => (a && a[c] ? a[c] : defaultValue || null), obj) as T | ||
} | ||
|
||
/** | ||
* drop-in replacement for _.without | ||
*/ | ||
export function without<T>(items: T[], item: T) { | ||
return items.filter(i => i !== item) | ||
} | ||
|
||
/** | ||
* drop-in replacement for _.isString | ||
* @param input | ||
*/ | ||
export function isString(input: any) { | ||
return typeof input === 'string' | ||
} | ||
|
||
/** | ||
* drop-in replacement for _.isString | ||
* @param input | ||
*/ | ||
export function isObject(input: any) { | ||
return typeof input === 'object' | ||
} | ||
|
||
/** | ||
* repalcement for _.xor | ||
* @param itemsA | ||
* @param itemsB | ||
*/ | ||
export function xor<T extends string | number>(itemsA: T[], itemsB: T[]): T[] { | ||
const map = new Map<T, number>() | ||
const insertItem = (item: T) => | ||
map.set(item, map.has(item) ? map.get(item)! + 1 : 1) | ||
itemsA.forEach(insertItem) | ||
itemsB.forEach(insertItem) | ||
|
||
const result: T[] = [] | ||
map.forEach((count, key) => { | ||
if (count === 1) { | ||
result.push(key) | ||
} | ||
}) | ||
return result | ||
} | ||
|
||
/** | ||
* replacement for _.intersection | ||
* @param itemsA | ||
* @param itemsB | ||
*/ | ||
export function intersection<T>(itemsA: T[], itemsB: T[]) { | ||
return itemsA.filter(t => itemsB.indexOf(t) > -1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/react-dnd-html5-backend/src/utils/__tests__/discount_lodash.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { memoize, union } from '../discount_lodash' | ||
|
||
describe('lodash replacement', () => { | ||
it('can memoize', () => { | ||
let count = 0 | ||
const fn = memoize(() => { | ||
if (count > 0) { | ||
throw new Error('too many invocations to memoized function') | ||
} | ||
count += 1 | ||
return 100 + 30 | ||
}) | ||
|
||
expect(fn()).toEqual(130) | ||
expect(fn()).toEqual(130) | ||
expect(fn()).toEqual(130) | ||
}) | ||
|
||
it('can compute union', () => { | ||
const result = union([1, 2, 1, 3, 1, 5], [7, 8, 7, 9]) | ||
expect(result).toEqual([1, 2, 3, 5, 7, 8, 9]) | ||
}) | ||
}) |
28 changes: 28 additions & 0 deletions
28
packages/react-dnd-html5-backend/src/utils/discount_lodash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function memoize<T>(fn: () => T): () => T { | ||
let result: T | null = null | ||
const memoized = () => { | ||
if (result == null) { | ||
result = fn() | ||
} | ||
return result | ||
} | ||
return memoized | ||
} | ||
|
||
/** | ||
* drop-in replacement for _.without | ||
*/ | ||
export function without<T>(items: T[], item: T) { | ||
return items.filter(i => i !== item) | ||
} | ||
|
||
export function union<T extends string | number>(itemsA: T[], itemsB: T[]) { | ||
const set = new Set<T>() | ||
const insertItem = (item: T) => set.add(item) | ||
itemsA.forEach(insertItem) | ||
itemsB.forEach(insertItem) | ||
|
||
const result: T[] = [] | ||
set.forEach(key => result.push(key)) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.