Skip to content

Commit

Permalink
Merge pull request #1314 from umbraco/chore/minor-naming-corrections
Browse files Browse the repository at this point in the history
Chore: Correcting last naming todos from my list
  • Loading branch information
nielslyngsoe authored Feb 29, 2024
2 parents 4f9bfbc + 9c11b12 commit d34b893
Show file tree
Hide file tree
Showing 93 changed files with 239 additions and 198 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbNumberState } from '@umbraco-cms/backoffice/observable-api';

// The Example Workspace Context Controller:
export class WorkspaceContextCounter extends UmbBaseController {
export class WorkspaceContextCounter extends UmbControllerBase {
// We always keep our states private, and expose the values as observables:
#counter = new UmbNumberState(0);
readonly counter = this.#counter.asObservable();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbWorkspaceAction } from '@umbraco-cms/backoffice/workspace';
import { EXAMPLE_COUNTER_CONTEXT } from './counter-workspace-context';

// The Example Incrementor Workspace Action Controller:
export class ExampleIncrementorWorkspaceAction extends UmbBaseController implements UmbWorkspaceAction {
export class ExampleIncrementorWorkspaceAction extends UmbControllerBase implements UmbWorkspaceAction {
// This method is executed
async execute() {
await this.consumeContext(EXAMPLE_COUNTER_CONTEXT, (context) => {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/app/app.context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { UmbAppContextConfig } from './app-context-config.interface.js';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';

export class UmbAppContext extends UmbBaseController {
export class UmbAppContext extends UmbControllerBase {
#serverUrl: string;
#backofficePath: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PackageResource, OpenAPI } from '@umbraco-cms/backoffice/external/backend-api';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { UmbBackofficeExtensionRegistry } from '@umbraco-cms/backoffice/extension-registry';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import type { ManifestBase } from '@umbraco-cms/backoffice/extension-api';
import { isManifestBaseType } from '@umbraco-cms/backoffice/extension-api';

// TODO: consider if this can be replaced by the new extension controllers
export class UmbServerExtensionRegistrator extends UmbBaseController {
export class UmbServerExtensionRegistrator extends UmbControllerBase {
#extensionRegistry: UmbBackofficeExtensionRegistry;
#apiBaseUrl = OpenAPI.BASE;

Expand Down
4 changes: 2 additions & 2 deletions src/libs/class-api/context-base.class.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UmbContextToken } from '../context-api/index.js';
import type { UmbControllerHost } from '../controller-api/index.js';
import type { UmbContext } from './context.interface.js';
import { UmbBaseController } from './controller-base.class.js';
import { UmbControllerBase } from './controller-base.class.js';

/**
* This base provides the necessary for a class to become a context-api controller.
Expand All @@ -11,7 +11,7 @@ export abstract class UmbContextBase<
ContextType,
GivenContextToken extends UmbContextToken<ContextType, ContextType> = UmbContextToken<ContextType, ContextType>,
>
extends UmbBaseController
extends UmbControllerBase
implements UmbContext
{
constructor(host: UmbControllerHost, contextToken: GivenContextToken | string) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/class-api/controller-base.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import { UmbClassMixin } from './class.mixin.js';
* This enables controllers to be added to the life cycle of this element.
*
*/
export abstract class UmbBaseController extends UmbClassMixin(EventTarget) implements UmbController {}
export abstract class UmbControllerBase extends UmbClassMixin(EventTarget) implements UmbController {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { UmbExtensionCondition } from '../condition/extension-condition.int
import type { UmbControllerHostElement } from '../../controller-api/controller-host-element.mixin.js';
import { UmbControllerHostElementMixin } from '../../controller-api/controller-host-element.mixin.js';
import { UmbBaseExtensionInitializer } from './index.js';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { customElement, html } from '@umbraco-cms/backoffice/external/lit';
import { UmbSwitchCondition } from '@umbraco-cms/backoffice/extension-registry';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
Expand Down Expand Up @@ -38,15 +38,15 @@ class UmbTestExtensionController extends UmbBaseExtensionInitializer {
}
}

class UmbTestConditionAlwaysValid extends UmbBaseController implements UmbExtensionCondition {
class UmbTestConditionAlwaysValid extends UmbControllerBase implements UmbExtensionCondition {
config: UmbConditionConfigBase;
constructor(args: { host: UmbControllerHost; config: UmbConditionConfigBase }) {
super(args.host);
this.config = args.config;
}
permitted = true;
}
class UmbTestConditionAlwaysInvalid extends UmbBaseController implements UmbExtensionCondition {
class UmbTestConditionAlwaysInvalid extends UmbControllerBase implements UmbExtensionCondition {
config: UmbConditionConfigBase;
constructor(args: { host: UmbControllerHost; config: UmbConditionConfigBase }) {
super(args.host);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createExtensionApi } from '../functions/index.js';
import type { UmbExtensionCondition } from '../condition/extension-condition.interface.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type {
UmbConditionConfigBase,
ManifestCondition,
Expand All @@ -21,7 +21,7 @@ import type { UmbObserverController } from '@umbraco-cms/backoffice/observable-a
export abstract class UmbBaseExtensionInitializer<
ManifestType extends ManifestWithDynamicConditions = ManifestWithDynamicConditions,
SubClassType = never,
> extends UmbBaseController {
> extends UmbControllerBase {
//
#promiseResolvers: Array<() => void> = [];
#manifestObserver!: UmbObserverController<ManifestType | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ManifestCondition, ManifestWithDynamicConditions, UmbConditionConf
import type { UmbExtensionCondition } from '../condition/extension-condition.interface.js';
import type { PermittedControllerType } from './index.js';
import { UmbBaseExtensionInitializer, UmbBaseExtensionsInitializer } from './index.js';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api';
import { customElement, html } from '@umbraco-cms/backoffice/external/lit';
Expand Down Expand Up @@ -65,15 +65,15 @@ class UmbTestExtensionsController<
}
}

class UmbTestConditionAlwaysValid extends UmbBaseController implements UmbExtensionCondition {
class UmbTestConditionAlwaysValid extends UmbControllerBase implements UmbExtensionCondition {
config: UmbConditionConfigBase;
constructor(args: { host: UmbControllerHost; config: UmbConditionConfigBase }) {
super(args.host);
this.config = args.config;
}
permitted = true;
}
class UmbTestConditionAlwaysInvalid extends UmbBaseController implements UmbExtensionCondition {
class UmbTestConditionAlwaysInvalid extends UmbControllerBase implements UmbExtensionCondition {
config: UmbConditionConfigBase;
constructor(args: { host: UmbControllerHost; config: UmbConditionConfigBase }) {
super(args.host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
UmbBaseExtensionInitializer,
UmbExtensionRegistry,
} from '@umbraco-cms/backoffice/extension-api';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';

export type PermittedControllerType<ControllerType extends { manifest: any }> = ControllerType & {
Expand All @@ -26,7 +26,7 @@ export abstract class UmbBaseExtensionsInitializer<
ManifestType extends ManifestBase = SpecificManifestTypeOrManifestBase<ManifestTypes, ManifestTypeName>,
ControllerType extends UmbBaseExtensionInitializer<ManifestType> = UmbBaseExtensionInitializer<ManifestType>,
MyPermittedControllerType extends ControllerType = PermittedControllerType<ControllerType>,
> extends UmbBaseController {
> extends UmbControllerBase {
#promiseResolvers: Array<() => void> = [];
#extensionRegistry: UmbExtensionRegistry<ManifestType>;
#type: ManifestTypeName | Array<ManifestTypeName>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, fixture } from '@open-wc/testing';
import { UmbExtensionRegistry } from '../registry/extension.registry.js';
import type { ManifestApi, ManifestWithDynamicConditions } from '../types/index.js';
import { UmbExtensionApiInitializer } from './index.js';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerHostElementMixin } from '@umbraco-cms/backoffice/controller-api';
import type { UmbControllerHostElement, UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { customElement, html } from '@umbraco-cms/backoffice/external/lit';
Expand All @@ -11,7 +11,7 @@ import { type ManifestSection, UmbSwitchCondition } from '@umbraco-cms/backoffic
@customElement('umb-test-controller-host')
class UmbTestControllerHostElement extends UmbControllerHostElementMixin(HTMLElement) {}

class UmbTestApiController extends UmbBaseController {
class UmbTestApiController extends UmbControllerBase {
public i_am_test_api_controller = true;

constructor(host: UmbControllerHost) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ManifestBase, ManifestBundle } from '../types/index.js';
import type { UmbExtensionRegistry } from '../registry/extension.registry.js';
import { loadManifestPlainJs } from '../functions/load-manifest-plain-js.function.js';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';

export class UmbBundleExtensionInitializer extends UmbBaseController {
export class UmbBundleExtensionInitializer extends UmbControllerBase {
#extensionRegistry;
#bundleMap = new Map();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ManifestEntryPoint } from '../types/index.js';
import type { UmbExtensionRegistry } from '../registry/extension.registry.js';
import { hasInitExport, loadManifestPlainJs } from '../functions/index.js';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbElement } from '@umbraco-cms/backoffice/element-api';

export class UmbEntryPointExtensionInitializer extends UmbBaseController {
export class UmbEntryPointExtensionInitializer extends UmbControllerBase {
#host;
#extensionRegistry;
#entryPointMap = new Map();
Expand Down
6 changes: 3 additions & 3 deletions src/libs/observable-api/states/deep-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createObservablePart } from '../utils/create-observable-part.function.j
import { deepFreeze } from '../utils/deep-freeze.function.js';
import type { MappingFunction } from '../types/mapping-function.type.js';
import type { MemoizationFunction } from '../types/memoization-function.type.js';
import { naiveObjectComparison } from '../utils/naive-object-comparison.function.js';
import { jsonStringComparison } from '../utils/json-string-comparison.function.js';
import { UmbBasicState } from './basic-state.js';

/**
Expand All @@ -28,7 +28,7 @@ export class UmbDeepState<T> extends UmbBasicState<T> {
mappingFunction: MappingFunction<T, ReturnType>,
memoizationFunction?: MemoizationFunction<ReturnType>,
) {
return createObservablePart(this._subject, mappingFunction, memoizationFunction ?? naiveObjectComparison);
return createObservablePart(this._subject, mappingFunction, memoizationFunction ?? jsonStringComparison);
}

/**
Expand All @@ -40,7 +40,7 @@ export class UmbDeepState<T> extends UmbBasicState<T> {
if (!this._subject) return;
const frozenData = deepFreeze(data);
// Only update data if its different than current data.
if (!naiveObjectComparison(frozenData, this._subject.getValue())) {
if (!jsonStringComparison(frozenData, this._subject.getValue())) {
this._subject.next(frozenData);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/observable-api/states/string-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MappingFunction, MemoizationFunction } from '../types/index.js';
import { createObservablePart } from '../utils/index.js';
import { createObservablePart, strictEqualityMemoization } from '../utils/index.js';
import { UmbBasicState } from './basic-state.js';

/**
Expand All @@ -17,6 +17,6 @@ export class UmbStringState<T> extends UmbBasicState<T | string> {
mappingFunction: MappingFunction<T | string, ReturnType>,
memoizationFunction?: MemoizationFunction<ReturnType>,
) {
return createObservablePart(this._subject, mappingFunction, memoizationFunction);
return createObservablePart(this._subject, mappingFunction, memoizationFunction ?? strictEqualityMemoization);
}
}
11 changes: 11 additions & 0 deletions src/libs/observable-api/utils/deep-freeze.function.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* Deep freeze an object and all its properties.
* @param {T} inObj - The object to deep freeze.
* @returns {T} - The deep frozen object.
* @description - Deep freezes an object and all its properties.
* @example <caption>Example of deep freezing an object.</caption>
* const myObject = {a: 1, b: {c: 2}};
* const frozenObject = deepFreeze(myObject);
* frozenObject.a = 3; // Throws an error.
* frozenObject.b.c = 4; // Throws an error.
*/
export const deepFreeze = Object.freeze(function deepFreezeImpl<T>(inObj: T): T {
if (inObj != null && typeof inObj === 'object') {
Object.freeze(inObj);
Expand Down
14 changes: 12 additions & 2 deletions src/libs/observable-api/utils/default-memoization.function.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { naiveObjectComparison } from './naive-object-comparison.function.js';
import { jsonStringComparison } from './json-string-comparison.function.js';

/**
* @export
* @method defaultMemoization
* @param {any} previousValue - The previous value to compare.
* @param {any} currentValue - The current value to compare.
* @returns {boolean} - Returns true if the values are identical.
* @description - Default memoization function to compare two values.
* This checks if the two values are of type 'object' (Array or Object) and compares them using a naive JSON string comparison.
* If not then it compares the two values using strict equality.
*/
export function defaultMemoization(previousValue: any, currentValue: any): boolean {
if (typeof previousValue === 'object' && typeof currentValue === 'object') {
return naiveObjectComparison(previousValue, currentValue);
return jsonStringComparison(previousValue, currentValue);
}
return previousValue === currentValue;
}
3 changes: 2 additions & 1 deletion src/libs/observable-api/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ export * from './create-observable-part.function.js';
export * from './deep-freeze.function.js';
export * from './default-memoization.function.js';
export * from './filter-frozen-array.function.js';
export * from './json-string-comparison.function.js';
export * from './merge-observables.function.js';
export * from './naive-object-comparison.function.js';
export * from './observe-multiple.function.js';
export * from './partial-update-frozen-array.function.js';
export * from './push-to-unique-array.function.js';
export * from './simple-hash-code.function.js';
export * from './strict-equality-memoization.function.js';
13 changes: 13 additions & 0 deletions src/libs/observable-api/utils/json-string-comparison.function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @export
* @method jsonStringComparison
* @param {unknown} a - The first object to compare.
* @param {unknown} b - The second object to compare.
* @returns {boolean} - Returns true if the JSON strings are identical.
* @description - Compares two objects by converting them to JSON strings.
* This is a JSON comparison and should only be used for simple objects.
* Meaning no class instances can take part in this data.
*/
export function jsonStringComparison(a: unknown, b: unknown): boolean {
return JSON.stringify(a) === JSON.stringify(b);
}
3 changes: 1 addition & 2 deletions src/libs/observable-api/utils/merge-observables.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type ArrayToObservableTypes<T extends Array<Observable<any>>> = {
* if observable1 has the value of 10 and observable2 has the value of 4, the mergedObservable will return the value of 14.
* if one of them changes the mergedObservable will return the new value.
*/

export function mergeObservables<
R,
SourceTypes extends Array<Observable<unknown>>,
Expand All @@ -38,7 +37,7 @@ export function mergeObservables<
): Observable<R> {
return combineLatest(sources).pipe(
map(mergeFunction as MappingFunction<unknown[], R>),
distinctUntilChanged(memoizationFunction || defaultMemoization),
distinctUntilChanged(memoizationFunction ?? defaultMemoization),
shareReplay(1),
);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @export
* @method strictEqualityMemoization
* @param {unknown} previousValue - The previous value to compare.
* @param {unknown} currentValue - The current value to compare.
* @returns {boolean} - Returns true if the values are identical.
* @description - Compares the two values using strict equality.
*/
export function strictEqualityMemoization(previousValue: unknown, currentValue: unknown): boolean {
return previousValue === currentValue;
}
4 changes: 2 additions & 2 deletions src/packages/audit-log/repository/audit-log.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controlle
import type { UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import type { AuditTypeModel, DirectionModel } from '@umbraco-cms/backoffice/external/backend-api';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';

export class UmbAuditLogRepository extends UmbBaseController {
export class UmbAuditLogRepository extends UmbControllerBase {
#dataSource: UmbAuditLogServerDataSource;
#notificationService?: UmbNotificationContext;
#init;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { UmbArrayState, UmbObjectState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost, UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import type { ManifestWorkspace, PropertyEditorConfigProperty } from '@umbraco-cms/backoffice/extension-registry';
import type { ManifestWorkspace, PropertyEditorSettingsProperty } from '@umbraco-cms/backoffice/extension-registry';

export class UmbBlockGridAreaTypeWorkspaceContext
extends UmbEditableWorkspaceContextBase<UmbBlockGridTypeAreaType>
Expand All @@ -29,7 +29,7 @@ export class UmbBlockGridAreaTypeWorkspaceContext
readonly name = this.#data.asObservablePart((data) => data?.alias);
readonly unique = this.#data.asObservablePart((data) => data?.key);

#properties = new UmbArrayState<PropertyEditorConfigProperty>([], (x) => x.alias);
#properties = new UmbArrayState<PropertyEditorSettingsProperty>([], (x) => x.alias);
readonly properties = this.#properties.asObservable();

constructor(host: UmbControllerHostElement, workspaceArgs: { manifest: ManifestWorkspace }) {
Expand Down
Loading

0 comments on commit d34b893

Please sign in to comment.