FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(sanity): remove lodash-es deep imports by osnoser1 · Pull Request #78 · limitless-angular/limitless-angular · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .json  (2) .mjs  (1) .ts  (8) .yaml  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion packages/sanity/ng-package.json
This file contains hidden or 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
Expand Up @@ -16,7 +16,6 @@
"@sanity/visual-editing-csm",
"@vercel/stega",
"dequal",
"lodash-es",
"xstate"
]
}
2 changes: 0 additions & 2 deletions packages/sanity/package.json
This file contains hidden or 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
Expand Up @@ -51,7 +51,6 @@
"@sanity/visual-editing-csm": "^3.0.9",
"@vercel/stega": "1.1.0",
"dequal": "^2.0.3",
"lodash-es": "^4.17.21",
"tslib": "^2.3.0",
"xstate": "^5.19.2"
},
Expand All @@ -67,7 +66,6 @@
"@sanity/client": "^7.22.1",
"@testing-library/angular": "^19.4.1",
"@testing-library/dom": "^10.4.0",
"@types/lodash-es": "^4.17.12",
"@types/node": "~22.19.20",
"angular-eslint": "^22.0.0",
"eslint": "^9.8.0",
Expand Down
This file contains hidden or 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
@@ -1,13 +1,13 @@
import { Injectable } from '@angular/core';
import { PortableTextBlock } from '@portabletext/types';
import { memoize } from 'lodash-es';

import {
MissingComponentHandler,
PortableTextAngularComponents,
Serializable,
} from '../types';
import { serializeBlock } from '../utils';
import { memoize } from '../utils/memoize';
import { unknownBlockStyleWarning } from '../warnings';
import { isPortableTextBlock } from '@portabletext/toolkit';

Expand Down
This file contains hidden or 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
Expand Up @@ -4,14 +4,14 @@ import {
PortableTextMarkDefinition,
PortableTextSpan,
} from '@portabletext/types';
import { memoize } from 'lodash-es';

import {
MissingComponentHandler,
PortableTextAngularComponents,
Serializable,
} from '../types';
import { serializeBlock } from '../utils';
import { memoize } from '../utils/memoize';
import { unknownListItemStyleWarning } from '../warnings';
import { isPortableTextListItemBlock } from '@portabletext/toolkit';

Expand Down
28 changes: 28 additions & 0 deletions packages/sanity/portabletext/src/utils/memoize.spec.ts
This file contains hidden or 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 @@
import { describe, expect, it, vi } from 'vitest';

import { memoize } from './memoize';

describe('memoize', () => {
it('returns the cached result for the same argument reference', () => {
const fn = vi.fn((value: { text: string }) => [value.text]);
const memoized = memoize(fn);
const value = { text: 'cached' };

const first = memoized(value);
const second = memoized(value);

expect(second).toBe(first);
expect(fn).toHaveBeenCalledOnce();
});

it('treats equal object values with different references as separate keys', () => {
const fn = vi.fn((value: { text: string }) => [value.text]);
const memoized = memoize(fn);

const first = memoized({ text: 'same value' });
const second = memoized({ text: 'same value' });

expect(second).not.toBe(first);
expect(fn).toHaveBeenCalledTimes(2);
});
});
15 changes: 15 additions & 0 deletions packages/sanity/portabletext/src/utils/memoize.ts
This file contains hidden or 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,15 @@
export function memoize<Arg, Result>(
fn: (arg: Arg) => Result,
): (arg: Arg) => Result {
const cache = new Map<Arg, Result>();

return (arg) => {
if (cache.has(arg)) {
return cache.get(arg) as Result;
}

const result = fn(arg);
cache.set(arg, result);
return result;
};
}
This file contains hidden or 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
Expand Up @@ -9,7 +9,7 @@ import type {
SanityClient,
SyncTag,
} from '@sanity/client';
import isEqual from 'lodash-es/isEqual';
import { dequal as isEqual } from 'dequal';
import {
EMPTY,
Observable,
Expand Down
This file contains hidden or 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
@@ -1,5 +1,6 @@
import { getQueryCacheKey } from './utils';
import { LiveQueriesService } from './live-queries.service';
import type { ContentSourceMap } from '@sanity/client';

describe('LiveQueriesService', () => {
it('tracks query subscriptions by query, params, and perspective', () => {
Expand Down Expand Up @@ -54,4 +55,40 @@ describe('LiveQueriesService', () => {

subscription.unsubscribe();
});

it('uses deep equality for source maps when deciding whether to update', () => {
const service = new LiveQueriesService();
const query = '*[_id == $id][0]';
const params = { id: 'post' };
const key = getQueryCacheKey(query, params, 'drafts');
const result = { title: 'Live' };
const sourceMap = {
documents: [{ _id: 'post', _type: 'post' }],
mappings: {
title: {
source: {
document: 0,
path: 0,
type: 'documentValue',
},
type: 'value',
},
},
paths: ['title'],
} satisfies ContentSourceMap;

expect(service.update(key, result, sourceMap, ['s1:post'])).toBe(true);
expect(
service.update(
key,
{ title: 'Live' },
{
...sourceMap,
documents: [{ _id: 'post', _type: 'post' }],
paths: ['title'],
},
['s1:post'],
),
).toBe(false);
});
});
This file contains hidden or 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
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import type { ContentSourceMap, QueryParams, SyncTag } from '@sanity/client';
import isEqual from 'lodash-es/isEqual';
import { dequal as isEqual } from 'dequal';
import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';

Expand Down
This file contains hidden or 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
Expand Up @@ -7,7 +7,7 @@ import {
type LoaderControllerMsg,
type LoaderNodeMsg,
} from '@sanity/presentation-comlink';
import isEqual from 'lodash-es/isEqual';
import { dequal as isEqual } from 'dequal';
import { BehaviorSubject, combineLatest, type Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';

Expand Down
28 changes: 7 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tools/angular-compat/pack.mjs
This file contains hidden or 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
Expand Up @@ -52,7 +52,6 @@ export function packCompatibilityArtifact() {
'@angular/compiler-cli': toolchain.compilerCliVersion,
'@angular/core': toolchain.angularVersion,
'@angular/router': toolchain.angularVersion,
'@types/lodash-es': packageJson.devDependencies['@types/lodash-es'],
'@types/node': packageJson.devDependencies['@types/node'],
'ng-packagr': toolchain.ngPackagrVersion,
typescript: toolchain.typescriptVersion,
Expand Down
Loading

Back | FazBrowse Home | New Git URL