Skip to content

Commit 94a1d30

Browse files
committed
Rename scheme to metadata
Really this is state metadata, not a schema. The word "schema" never described this well.
1 parent 591f7f0 commit 94a1d30

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/BaseControllerV2.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type Listener<T> = (state: T, patches: Patch[]) => void;
1313

1414
export type Anonymizer<T> = (value: T) => T;
1515

16-
export type Schema<T> = {
16+
export type StateMetadata<T> = {
1717
[P in keyof T]: {
1818
persist: boolean;
1919
anonymous: boolean | Anonymizer<T[P]>;
@@ -28,18 +28,18 @@ export class BaseController<S extends Record<string, any>> {
2828

2929
private internalListeners: Set<Listener<S>> = new Set();
3030

31-
public readonly schema: Schema<S>;
31+
public readonly metadata: StateMetadata<S>;
3232

3333
/**
3434
* Creates a BaseController instance.
3535
*
3636
* @param state - Initial controller state
37-
* @param schema - State schema, describing how to "anonymize" the state,
37+
* @param metadata - State metadata, describing how to "anonymize" the state,
3838
* and which parts should be persisted.
3939
*/
40-
constructor(state: S, schema: Schema<S>) {
40+
constructor(state: S, metadata: StateMetadata<S>) {
4141
this.internalState = state;
42-
this.schema = schema;
42+
this.metadata = metadata;
4343
}
4444

4545
/**
@@ -109,23 +109,23 @@ function isAnonymizingFunction<T>(x: boolean | Anonymizer<T>): x is Anonymizer<T
109109
return typeof x === 'function';
110110
}
111111

112-
export function getAnonymizedState<S extends Record<string, any>>(state: S, schema: Schema<S>) {
112+
export function getAnonymizedState<S extends Record<string, any>>(state: S, metadata: StateMetadata<S>) {
113113
return Object.keys(state).reduce((anonymizedState, _key) => {
114114
const key: keyof S = _key; // https://stackoverflow.com/questions/63893394/string-cannot-be-used-to-index-type-t
115-
const schemaValue = schema[key].anonymous;
116-
if (isAnonymizingFunction(schemaValue)) {
117-
anonymizedState[key] = schemaValue(state[key]);
118-
} else if (schemaValue) {
115+
const metadataValue = metadata[key].anonymous;
116+
if (isAnonymizingFunction(metadataValue)) {
117+
anonymizedState[key] = metadataValue(state[key]);
118+
} else if (metadataValue) {
119119
anonymizedState[key] = state[key];
120120
}
121121
return anonymizedState;
122122
}, {} as Partial<S>);
123123
}
124124

125-
export function getPersistentState<S extends Record<string, any>>(state: S, schema: Schema<S>) {
125+
export function getPersistentState<S extends Record<string, any>>(state: S, metadata: StateMetadata<S>) {
126126
return Object.keys(state).reduce((persistedState, _key) => {
127127
const key: keyof S = _key; // https://stackoverflow.com/questions/63893394/string-cannot-be-used-to-index-type-t
128-
if (schema[key].persist) {
128+
if (metadata[key].persist) {
129129
persistedState[key] = state[key];
130130
}
131131
return persistedState;

0 commit comments

Comments
 (0)