This commit is contained in:
Lone Iversen
2023-01-25 14:01:26 +01:00
parent 709ffc828f
commit a42d0e7b6f
78 changed files with 221 additions and 888 deletions

View File

@@ -1,9 +1,18 @@
import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { UmbLitElement } from './lit-element.element';
import type { UmbControllerHostInterface } from '@umbraco-cms/controller';
@customElement('umb-context-provider')
export class UmbContextProviderElement extends UmbLitElement {
/**
* The value to provide to the context.
* @required
*/
@property({ type: Object, attribute: false })
create?: (host:UmbControllerHostInterface) => unknown;
/**
* The value to provide to the context.
* @required
@@ -23,7 +32,9 @@ export class UmbContextProviderElement extends UmbLitElement {
if (!this.key) {
throw new Error('The key property is required.');
}
if (!this.value) {
if (this.create) {
this.value = this.create(this);
} else if (!this.value) {
throw new Error('The value property is required.');
}
this.provideContext(this.key, this.value);

View File

@@ -1,3 +1,5 @@
import { UmbExtensionRegistry } from './registry/extension.registry';
export * from './registry/extension.registry';
export * from './create-extension-element.function';
export * from './has-default-export.function';
@@ -6,3 +8,5 @@ export * from './is-manifest-elementable-type.function';
export * from './is-manifest-js-type.function';
export * from './is-manifest-loader-type.function';
export * from './load-extension.function';
export const umbExtensionsRegistry = new UmbExtensionRegistry();

View File

@@ -1,4 +1 @@
import { UmbExtensionRegistry } from '@umbraco-cms/extensions-api';
export * from './models';
export const umbExtensionsRegistry = new UmbExtensionRegistry();

View File

@@ -1,5 +1,5 @@
import { DeepState } from "./deep-state";
import { appendToFrozenArray } from "./append-to-frozen-array.method";
import { pushToUniqueArray } from "./push-to-unique-array.method";
/**
* @export
@@ -21,15 +21,15 @@ export class ArrayState<T> extends DeepState<T[]> {
/**
* @method append
* @param {unknown} unique - The unique value to remove.
* @returns ArrayState<T>
* @return {ArrayState<T>} Reference to it self.
* @description - Remove some new data of this Subject.
* @example <caption>Example remove entry with key '1'</caption>
* const data = [
* { key: 1, value: 'foo'},
* { key: 2, value: 'bar'}
* ];
* const mySubject = new ArrayState(data, (x) => x.key);
* mySubject.remove([1]);
* const myState = new ArrayState(data, (x) => x.key);
* myState.remove([1]);
*/
remove(uniques: unknown[]) {
let next = this.getValue();
@@ -51,7 +51,7 @@ export class ArrayState<T> extends DeepState<T[]> {
/**
* @method filter
* @param {unknown} filterMethod - The unique value to remove.
* @returns ArrayState<T>
* @return {ArrayState<T>} Reference to it self.
* @description - Remove some new data of this Subject.
* @example <caption>Example remove entry with key '1'</caption>
* const data = [
@@ -59,8 +59,8 @@ export class ArrayState<T> extends DeepState<T[]> {
* { key: 2, value: 'bar'},
* { key: 3, value: 'poo'}
* ];
* const mySubject = new ArrayState(data, (x) => x.key);
* mySubject.filter((entry) => entry.key !== 1);
* const myState = new ArrayState(data, (x) => x.key);
* myState.filter((entry) => entry.key !== 1);
*
* Result:
* [
@@ -75,48 +75,55 @@ export class ArrayState<T> extends DeepState<T[]> {
}
/**
* @method append
* @param {Partial<T>} partialData - A object containing some of the data for this Subject.
* @returns ArrayState<T>
* @method appendOne
* @param {T} entry - new data to be added in this Subject.
* @return {ArrayState<T>} Reference to it self.
* @description - Append some new data to this Subject.
* @example <caption>Example append some data.</caption>
* const data = [
* { key: 1, value: 'foo'},
* { key: 2, value: 'bar'}
* ];
* const mySubject = new ArrayState(data);
* mySubject.append({ key: 1, value: 'replaced-foo'});
* const myState = new ArrayState(data);
* myState.append({ key: 1, value: 'replaced-foo'});
*/
appendOne(entry: T) {
this.next(appendToFrozenArray(this.getValue(), entry, this._getUnique))
const next = [...this.getValue()];
if(this._getUnique) {
pushToUniqueArray(next, entry, this._getUnique);
} else {
next.push(entry);
}
this.next(next);
return this;
}
/**
* @method append
* @param {T[]} entries - A array of new data to be added in this Subject.
* @returns ArrayState<T>
* @return {ArrayState<T>} Reference to it self.
* @description - Append some new data to this Subject, if it compares to existing data it will replace it.
* @example <caption>Example append some data.</caption>
* const data = [
* { key: 1, value: 'foo'},
* { key: 2, value: 'bar'}
* ];
* const mySubject = new ArrayState(data);
* mySubject.append([
* const myState = new ArrayState(data);
* myState.append([
* { key: 1, value: 'replaced-foo'},
* { key: 3, value: 'another-bla'}
* ]);
*/
append(entries: T[]) {
// TODO: stop calling appendOne for each but make sure to handle this in one.
entries.forEach(x => this.appendOne(x))
/*
const unFrozenDataSet = [...this.getValue()];
this.next(unFrozenDataSet);
*/
if(this._getUnique) {
const next = [...this.getValue()];
entries.forEach(entry => {
pushToUniqueArray(next, entry, this._getUnique!);
});
this.next(next);
} else {
this.next([...this.getValue(), ...entries]);
}
return this;
}
}

View File

@@ -12,15 +12,17 @@ import { DeepState } from "./deep-state";
export class ObjectState<T> extends DeepState<T> {
/**
* @method append
* @param {Partial<T>} partialData - A object containing some of the data for this Subject.
* @method update
* @param {Partial<T>} partialData - A object containing some of the data to update in this Subject.
* @description - Append some new data to this Object.
* @return {ObjectState<T>} Reference to it self.
* @example <caption>Example append some data.</caption>
* const data = {key: 'myKey', value: 'myInitialValue'};
* const mySubject = new ObjectState(data)
* mySubject.append({value: 'myNewValue'})
* const myState = new ObjectState(data);
* myState.update({value: 'myNewValue'});
*/
update(partialData: Partial<T>) {
this.next({ ...this.getValue(), ...partialData });
return this;
}
}

View File

@@ -1,11 +1,8 @@
import { UmbContextProviderController } from "../context-api/provide/context-provider.controller";
import { UmbControllerHostInterface } from "../controller/controller-host.mixin";
import { UmbContextProviderController } from '@umbraco-cms/context-api';
import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbStoreBase {
constructor (protected _host: UmbControllerHostInterface, public readonly storeAlias: string) {
constructor(protected _host: UmbControllerHostInterface, public readonly storeAlias: string) {
new UmbContextProviderController(_host, storeAlias, this);
}
}