Skip to content

Commit

Permalink
Fix default options
Browse files Browse the repository at this point in the history
Fix deep-assign utility
Fixes regression in #123
  • Loading branch information
simonwep committed Jul 5, 2021
1 parent 8e7774c commit 754f653
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
behaviour: {
overlap: 'invert',
intersect: 'touch',
startThreshold: 10,
startThreshold: {x: 10, y: 10},
scrolling: {
speedDivider: 10,
manualSpeed: 750
Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface SelectionOptions {
features: Features;
}

export type PartialSelectionOptions = Partial<SelectionOptions> & {
export type PartialSelectionOptions = Partial<Omit<SelectionOptions, 'behaviour' | 'features'>> & {
behaviour?: Partial<Behaviour>;
features?: Partial<Features>;
}
13 changes: 6 additions & 7 deletions packages/vanilla/src/utils/deep-assign.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
export const deepAssign = <O>(target: O, source: any): O => {
const result: Record<any, unknown> = {};

for (const [key, value] of Object.entries(target)) {
export const deepAssign = (target: any, source: any): any => {
for (const [key, value] of Object.entries(source)) {

// Use the default value if there's no value specified
result[key] = source[key] === undefined ? target[key as keyof O] :
target[key] = value === undefined ? target[key as keyof O] :

// Check if it's a nested object and merge if required
(typeof value === 'object' && value !== null && !Array.isArray(value)) ?
deepAssign(value as O, source[key] as Partial<O>) : source[key];
deepAssign(target[key], source[key] as Partial<O>) :
source[key];
}

return result as O;
return target;
};

0 comments on commit 754f653

Please sign in to comment.