Skip to content

Commit 1ab1ba3

Browse files
committed
perf: remove metadata definition class
clean up unneeded base class files
1 parent a9d7412 commit 1ab1ba3

35 files changed

+151
-362
lines changed

projects/ngx-meta/src/core/public-api.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ export {
66
provideCore as provideNgxMetaCore,
77
withDefaults as withNgxMetaDefaults,
88
} from './src/provide-core'
9-
export * from './src/base-scoped-metadata'
109
export * from './src/composable-meta-property'
1110
export * from './src/global-metadata'
12-
export * from './src/global-metadata-definition'
1311
export * from './src/global-metadata-image'
1412
export * from './src/global-metadata-key'
13+
export * from './src/make-global-metadata'
14+
export * from './src/make-metadata'
1515
export * from './src/meta-content'
1616
export * from './src/meta-property'
1717
export * from './src/meta.service'
18+
export * from './src/metadata-provider'
1819
export * from './src/metadata'
19-
export * from './src/metadata-definition'
2020
export * from './src/metadata-setter'
2121
export * from './src/metadata-values'
2222
export * from './src/metadata.service'
23-
export * from './src/provide-metadata'
2423
export * from './src/provide-metadata-factory'
25-
export * from './src/scoped-metadata-definition'
2624
export * from './src/string-key-of'

projects/ngx-meta/src/core/src/__tests__/make-global-metadata-definition.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { MetadataProvider } from '../metadata-provider'
2+
import { makeGlobalMetadata } from '../make-global-metadata'
3+
4+
export function makeMetadataProvider<T, Id extends string>(
5+
opts: {
6+
id?: Id
7+
spyName?: string
8+
} = {},
9+
) {
10+
const id = opts.id ?? 'dummy'
11+
const metadata: MetadataProvider<T> = {
12+
metadata: makeGlobalMetadata(id),
13+
set: jasmine.createSpy(opts.spyName ?? id),
14+
}
15+
return metadata
16+
}

projects/ngx-meta/src/core/src/__tests__/make-metadata.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

projects/ngx-meta/src/core/src/__tests__/make-scoped-metadata-definition.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

projects/ngx-meta/src/core/src/base-global-metadata.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

projects/ngx-meta/src/core/src/base-metadata.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

projects/ngx-meta/src/core/src/base-scoped-metadata.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

projects/ngx-meta/src/core/src/global-metadata-definition.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Metadata } from './metadata'
2+
3+
export const makeGlobalMetadata = <Global extends string = string>(
4+
global: Global,
5+
): Metadata => ({ id: global, jsonPath: [global] })
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Metadata } from './metadata'
2+
3+
export const makeMetadata = <Global extends string = string>(
4+
jsonPath: ReadonlyArray<string>,
5+
global?: Global,
6+
): Metadata => ({
7+
id: jsonPath.join('.'),
8+
jsonPath,
9+
global,
10+
})

projects/ngx-meta/src/core/src/metadata-definition.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

projects/ngx-meta/src/core/src/metadata-json-resolver.spec.ts

Lines changed: 40 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { TestBed } from '@angular/core/testing'
22
import { MetadataJsonResolver } from './metadata-json-resolver'
33
import { MetadataValues } from './metadata-values'
4-
import { MetadataDefinition } from './metadata-definition'
5-
import { makeScopedMetadataDefinition } from './__tests__/make-scoped-metadata-definition'
6-
import { makeGlobalMetadataDefinition } from './__tests__/make-global-metadata-definition'
4+
import { Metadata } from './metadata'
5+
import { makeMetadata } from './make-metadata'
6+
import { makeGlobalMetadata } from './make-global-metadata'
77

88
describe('MetadataJsonResolver', () => {
99
let sut: MetadataJsonResolver
@@ -13,41 +13,34 @@ describe('MetadataJsonResolver', () => {
1313
})
1414

1515
describe('get', () => {
16-
const scope = 'scope'
16+
const key = 'key'
17+
const subKey = 'subKey'
1718
const global = 'global'
18-
const name = 'name'
1919
const value = 'value'
2020

2121
function testGlobalMayBeRetrieved(
22-
metadataDefinition: MetadataDefinition,
22+
metadata: Metadata,
2323
values: MetadataValues,
2424
) {
2525
describe('when global is not defined', () => {
2626
it('should return undefined', () => {
27-
expect(sut.get(metadataDefinition, values)).toBeUndefined()
27+
expect(sut.get(metadata, values)).toBeUndefined()
2828
})
2929
})
3030

3131
describe('when global is defined', () => {
32-
const metadataDefinitionWithGlobal = makeScopedMetadataDefinition({
33-
...metadataDefinition,
34-
global,
35-
})
32+
const metadataWithGlobal = makeMetadata(metadata.jsonPath, global)
3633

3734
describe('but global value does not exist', () => {
3835
it('should return undefined', () => {
39-
expect(
40-
sut.get(metadataDefinitionWithGlobal, values),
41-
).toBeUndefined()
36+
expect(sut.get(metadataWithGlobal, values)).toBeUndefined()
4237
})
4338
})
4439
describe('and global value exists', () => {
4540
const valuesWithGlobal = { [global]: value, ...values }
4641

4742
it('should return global value', () => {
48-
expect(
49-
sut.get(metadataDefinitionWithGlobal, valuesWithGlobal),
50-
).toEqual(value)
43+
expect(sut.get(metadataWithGlobal, valuesWithGlobal)).toEqual(value)
5144
})
5245
})
5346
})
@@ -58,123 +51,82 @@ describe('MetadataJsonResolver', () => {
5851
const values = undefined
5952

6053
it('should return undefined', () => {
61-
expect(
62-
sut.get(makeGlobalMetadataDefinition(), values),
63-
).toBeUndefined()
54+
expect(sut.get(makeGlobalMetadata('dummy'), values)).toBeUndefined()
6455
})
6556
})
66-
describe('like when scope does not exist', () => {
67-
const metadataDefinition = makeScopedMetadataDefinition({
68-
scope,
69-
})
57+
describe('like when key does not exist', () => {
58+
const metadata = makeMetadata([key])
7059
const values = {}
7160

72-
testGlobalMayBeRetrieved(metadataDefinition, values)
61+
testGlobalMayBeRetrieved(metadata, values)
7362
})
7463

75-
describe('like when scope is defined but property name does not exist', () => {
76-
const metadataDefinition = makeScopedMetadataDefinition({
77-
scope,
78-
name,
79-
})
64+
describe('like when key is defined but sub key does not exist', () => {
65+
const metadata = makeMetadata([key, subKey])
8066
const values = {
81-
[scope]: {},
67+
[key]: {},
8268
}
83-
testGlobalMayBeRetrieved(metadataDefinition, values)
69+
testGlobalMayBeRetrieved(metadata, values)
8470
})
8571

86-
describe('like when scope is null', () => {
87-
const metadataDefinition = makeScopedMetadataDefinition({
88-
scope,
89-
})
90-
91-
const values = { [scope]: null }
72+
describe('like when key is null', () => {
73+
const metadata = makeMetadata([key])
74+
const values = { [key]: null }
9275

9376
it('should return null', () => {
94-
expect(sut.get(metadataDefinition, values)).toBeNull()
77+
expect(sut.get(metadata, values)).toBeNull()
9578
})
9679
})
9780

98-
describe('like when scope value is null and there is sub scope', () => {
99-
const metadataDefinition = makeScopedMetadataDefinition({
100-
scope: `${scope}.subScope`,
101-
name,
102-
})
103-
104-
const values = { [scope]: null }
81+
describe('like when key is null and there is sub key', () => {
82+
const metadata = makeMetadata([key, subKey, 'dummy'])
83+
const values = { [key]: null }
10584

10685
it('should return null', () => {
107-
expect(sut.get(metadataDefinition, values)).toBeNull()
86+
expect(sut.get(metadata, values)).toBeNull()
10887
})
10988
})
11089

111-
describe('like when scope is not an object', () => {
112-
const metadataDefinition = makeScopedMetadataDefinition({ scope })
90+
describe('like when value in key is not an object', () => {
91+
const metadata = makeMetadata([key, subKey])
11392
const values = {
114-
[scope]: 42,
93+
[key]: 42,
11594
}
116-
testGlobalMayBeRetrieved(metadataDefinition, values)
95+
testGlobalMayBeRetrieved(metadata, values)
11796
})
11897
})
11998

12099
describe('when specific value is defined', () => {
121-
describe('like when scope does not contain sub scopes', () => {
122-
const metadataDefinition = makeScopedMetadataDefinition({
123-
scope,
124-
name,
125-
})
100+
describe('like when there is a key and sub key', () => {
101+
const metadata = makeMetadata([key, subKey])
126102

127103
const values = {
128-
[scope]: {
129-
[name]: value,
104+
[key]: {
105+
[subKey]: value,
130106
},
131107
}
132108

133-
it('should return value using scope and name as keys', () => {
134-
expect(sut.get(metadataDefinition, values)).toEqual(value)
109+
it('should return value using key and sub key as path', () => {
110+
expect(sut.get(metadata, values)).toEqual(value)
135111
})
136112
})
137113

138-
describe('like when scope contains sub scopes', () => {
139-
const subScope = 'subScope'
140-
const metadataDefinition = makeScopedMetadataDefinition({
141-
scope: `${scope}.${subScope}`,
142-
name,
143-
})
144-
145-
const values = {
146-
[scope]: {
147-
[subScope]: {
148-
[name]: value,
149-
},
150-
},
151-
}
152-
153-
it('should return value using sub scope, scope and name as keys', () => {
154-
expect(sut.get(metadataDefinition, values)).toEqual(value)
155-
})
156-
})
157114
describe('and it is and object, and a global object exists too', () => {
158115
const valueObject = { value: 'value', prop: 'value' }
159116
const globalValueObject = {
160117
globalValue: 'globalValue',
161118
prop: 'globalValue',
162119
}
163-
const metadataDefinition = makeScopedMetadataDefinition({
164-
scope,
165-
name,
166-
global,
167-
})
168-
120+
const metadata = makeMetadata([key, subKey], global)
169121
const values = {
170122
[global]: globalValueObject,
171-
[scope]: {
172-
[name]: valueObject,
123+
[key]: {
124+
[subKey]: valueObject,
173125
},
174126
}
175127

176128
it('should merge both objects, with specific value taking priority', () => {
177-
expect(sut.get(metadataDefinition, values)).toEqual({
129+
expect(sut.get(metadata, values)).toEqual({
178130
...globalValueObject,
179131
...valueObject,
180132
})

0 commit comments

Comments
 (0)