Skip to content

Commit

Permalink
Remove deprecated changedTo method
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarbara committed Oct 21, 2023
1 parent 7956ded commit c5529c0
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 66 deletions.
2 changes: 0 additions & 2 deletions packages/tree-changes/src/helpers.ts
Expand Up @@ -61,8 +61,6 @@ export function compareValues<K = Key>(
const primary = type === 'added' ? left : right;
const secondary = type === 'added' ? right : left;

// console.log({ primary, secondary });

if (!is.nullOrUndefined(value)) {
if (is.defined(primary)) {
// check if nested data matches
Expand Down
20 changes: 1 addition & 19 deletions packages/tree-changes/src/index.ts
Expand Up @@ -72,24 +72,6 @@ export default function treeChanges<P extends Data, D extends Data, K = KeyType<
}
};

/**
* @deprecated
* Use "changed" instead
*/
const changedTo = (key: K | string, actual: Value): boolean => {
if (!is.defined(key)) {
return false;
}

/* istanbul ignore next */
if (process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn('`changedTo` is deprecated! Replace it with `change`');
}

return changed(key, actual);
};

const decreased = (key: K, actual?: Value, previous?: Value): boolean => {
if (!is.defined(key)) {
return false;
Expand Down Expand Up @@ -147,7 +129,7 @@ export default function treeChanges<P extends Data, D extends Data, K = KeyType<
}
};

return { added, changed, changedFrom, changedTo, decreased, emptied, filled, increased, removed };
return { added, changed, changedFrom, decreased, emptied, filled, increased, removed };
}

export type { Data, KeyType, TreeChanges, Value } from './types';
5 changes: 0 additions & 5 deletions packages/tree-changes/src/types.ts
Expand Up @@ -25,11 +25,6 @@ export interface TreeChanges<K> {
added: (key?: K, value?: Value) => boolean;
changed: (key?: K | string, actual?: Value, previous?: Value) => boolean;
changedFrom: (key: K | string, previous: Value, actual?: Value) => boolean;
/**
* @deprecated
* Use "changed" instead.
*/
changedTo: (key: K | string, actual: Value) => boolean;
decreased: (key: K, actual?: Value, previous?: Value) => boolean;
emptied: (key?: K) => boolean;
filled: (key?: K) => boolean;
Expand Down
40 changes: 0 additions & 40 deletions packages/tree-changes/test/index.spec.ts
Expand Up @@ -284,46 +284,6 @@ describe('tree-changes', () => {
});
});

describe('changedTo', () => {
it('should handle calls without the `key` parameter', () => {
const { changedTo } = treeChanges(A, B);

// @ts-ignore
expect(changedTo()).toBe(false);
});

it('with arrays', () => {
const { changedTo } = treeChanges(A.versions, B.versions);

expect(changedTo(0, '0.1')).toBe(false);
expect(changedTo(1, 0.6)).toBe(true);
expect(changedTo(1, 0.5)).toBe(false);
expect(changedTo(2, 0.9)).toBe(true);
expect(changedTo('3.id', '2.0.0')).toBe(true);
});

it('with objects', () => {
const { changedTo } = treeChanges(A, B);

expect(changedTo('status', 'idle')).toBe(false);
expect(changedTo('status', ['ready', 'done'])).toBe(true);

expect(changedTo('hasData', false)).toBe(false);
expect(changedTo('hasData', true)).toBe(true);

expect(changedTo('data', { a: 1 })).toBe(false);
expect(changedTo('data', '')).toBe(false);

expect(changedTo('sort.status', 'running')).toBe(false);
expect(changedTo('sort.status', 'loaded')).toBe(true);

expect(changedTo('sort.data.0.type', 'desc')).toBe(true);
expect(changedTo('sort.data.1.type', 'asc')).toBe(true);

expect(changedTo('retries', 1)).toBe(true);
});
});

describe('decreased', () => {
it('should handle calls without the `key` parameter', () => {
const { decreased } = treeChanges(A, B);
Expand Down

0 comments on commit c5529c0

Please sign in to comment.