@acoustic-content-sdk/redux-utils 中文文档教程

发布于 4年前 浏览 10 更新于 3年前

npm

帮助处理 redux 状态的实用函数的实现。

Immutability

redux 模式的核心原则之一是保持所有状态不可变。 这意味着当更新一个值时,我们需要复制受影响的对象。 以下函数有助于限制这些副本的大小。

Updater

createUpdater 创建对象的包装器。 这个包装器允许设置或删除包装对象的(深层)属性而不改变它。 更新程序确保只创建最小的浅拷贝集。

示例:

const myObject={...};
const updater = createUpdater(myObject);

updater.set('elements.text.value', 'newValue');

const newObject = updater.get();

更新程序的工作方式类似于 immer 但没有开销。

Invariance Checks

在开发过程中,重要的是要验证对象没有发生变化。 使用不变性检查器对此进行测试,但出于性能原因,请确保不要在生产构建中包含这些检查。

Example:

const inv = invarianceChecker(myObject);
// do some operations

// validate that myObject has not been mutated
assert(inv());

API Documentation

API Documentation

Home > @acoustic-content-sdk/redux-utils

redux-utils package

帮助处理 redux 状态的实用函数的实现。

Functions

Function Description
createBreadcrumb(aId, aSelParent, aSelId) Constructs a breadcrumb trail starting at a particular ID
createUpdater(aValue, aLogSvc) Constructs a function that updates one or more values in a json object.
equalsByRevision(aLeft, aRight)
getNavSelectors(aJson$, aLogSvc) Returns selectors that access parent and child nodes from a navigation structure
invarianceChecker(aValue) Creates a function that validates that an object has not changed. Note that this should only be used for debugging purposes, since it makes a deep copy of the value to test for the invariance
isDraftId(aAuthoringId) Tests if the authoring ID has a draft suffix
isNotFromDataBase(aValue) Tests if a value is not from a database
isNotRoot(aId)
markAsFromDataBase(aValue) Adds a key to the item marking it as coming from the local data base
removeArrayItemByAccessor(aAccessor, aItem, aUser)
removeDataBaseMarker(aValue) Removes the database marker from the object
removeRecord() Creates a reducer that removes a key from a record
rxElementType(aTypeResolver, aLogSvc, aScheduler) Resolves the element type, either directly from the element or from the authoring type
rxLogDiff(aLogger)
rxResolveAuthoringItems(idOrItem, resolveItem, resolveAsset, aLogSvc, scheduler) Resolves the item and all referenced items and assets
selectByDeliveryId(aId) Constructs a selector that validates that the ID is a delivery ID (not a draft ID) and selects based on that ID from the state
serializeDiff(aOld, aNew, aSameStyle, aNewStyle, aDeletedStyle) Serializes the differences between two JSON objects
sortAuthoringItems(aResult) Performs a topological sort on a set of resolved items
updateGenericProperties(aItem, aUser) Updates properties of the item that depend on the environment
updateImageElement(aAccessor, aItem, aAsset)
updateRecord(aKey, aPredicate) Creates a reducer that adds an item to a record
updateSingleItem(aPredicate)
updateValueByAccessor(aAccessor, aValue, aItem, aUser) Updates a single property based on the accessor expression.

Interfaces

Interface Description
ItemWithId
ItemWithLinkedDocId
ItemWithRevision
NavigationJson
NavSelectors Interface that exposes selectors to the navigation structure
ResolvedNode
Updater Facade that offers the modification functions for a json object. The original JSON object will not be modified and the modified object will only contain the minimum number of modifications.

Variables

Variable Description
addToSetEpic Constructs an epic that convers an ADD action to a SET action
cloneAuthoringItems Basically a re-export of the clone functionality to have it all clean inside this one function
DB_KEY
DB_VALUE
ensureDraftId Makes sure to end the ID with a draft suffix
getDeliveryId Returns the delivery ID from an authoring ID, i.e. strips off the ':draft' suffix from the ID
getDeliveryIdFromAuthoringItem Returns the delivery ID from an authoring item.
getValueByAccessor Retrieves a property value by accessor
keyById Extract the delivery ID of the draft
ROOT_ID
selectClassification Extracts the classification property
updateItemsWithRevision

Type Aliases

Type Alias Description
AddRecordReducer Reducer function that adds an item to a record
AuthoringItem
ItemReducer Reducer function that updates an item
RemoveRecordReducer Reducer function that adds an item to a record
ResolutionResult
ResolveAuthoringAsset
ResolveAuthoringContentItem

Home > @acoustic-content-sdk/redux-utils > createBreadcrumb

createBreadcrumb() function

构建从特定 ID 开始的面包屑路径

签名:

export declare function createBreadcrumb<T>(aId: string, aSelParent: UnaryFunction<string, Observable<T>>, aSelId: UnaryFunction<T, string>): Observable<T[]>;

Parameters

Parameter Type Description
aId string the start ID
aSelParent UnaryFunction&lt;string, Observable&lt;T&gt;&gt; selector function for the parent node
aSelId UnaryFunction&lt;T, string&gt; selector function for the ID from a parent node

返回:

Observable ;

the breadcrumb trail

Home > @acoustic-content-sdk/redux-utils > createUpdater

createUpdater() function

构造一个更新 json 对象中的一个或多个值的函数。

Signature:

export declare function createUpdater<T>(aValue: T, aLogSvc?: LoggerService): Updater<T>;

Parameters

Parameter Type Description
aValue T the JSON structure to update
aLogSvc LoggerService

Returns:

Updater

updater functions

首页 > @acoustic-content-sdk/redux-utils > equalsByRevision

equalsByRevision() function

Signature:

export declare function equalsByRevision(aLeft: ItemWithRevision, aRight: ItemWithRevision): boolean;

Parameters

Parameter Type Description
aLeft ItemWithRevision
aRight ItemWithRevision

Returns:

boolean

主页 > @acoustic-content-sdk/redux-utils > getNavSelectors

getNavSelectors() function

返回从导航结构访问父节点和子节点的选择器

签名:

export declare function getNavSelectors(aJson$: Observable<NavigationJson>, aLogSvc?: LoggerService): NavSelectors;

Parameters

Parameter Type Description
aJson$ Observable&lt;NavigationJson&gt; the JSON that represents the navigation
aLogSvc LoggerService optional logger service

返回:

NavSelectors

the selectors

Home > @acoustic-content-sdk/redux-utils > invarianceChecker

invarianceChecker() function

创建一个函数来验证对象是否未更改。 请注意,这应该仅用于调试目的,因为它对值进行深度复制以测试不变性

Signature:

export declare function invarianceChecker(aValue: any): Generator<boolean>;

Parameters

Parameter Type Description
aValue any the value to test

Returns:

Generator;

the validator

Home > @acoustic-content-sdk/redux-utils > isDraftId

isDraftId() function

测试创作 ID 是否有草稿后缀

签名:

export declare function isDraftId(aAuthoringId: string): boolean;

Parameters

Parameter Type Description
aAuthoringId string the ID

返回:

boolean

true if we have a draft suffix, else false

Home > @acoustic-content-sdk/redux-utils > isNotFromDataBase

isNotFromDataBase() function

测试值是否来自数据库

签名:

export declare function isNotFromDataBase(aValue: any): boolean;

Parameters

Parameter Type Description
aValue any the value

返回:

boolean

true if the value exists and if it is not from the database, else false

Home > @acoustic-content-sdk/redux-utils > isNotRoot

isNotRoot() function

Signature:

export declare function isNotRoot(aId: string): boolean;

Parameters

Parameter Type Description
aId string

Returns:

boolean

主页 > @acoustic-content-sdk/redux-utils > markAsFromDataBase

markAsFromDataBase() function

向项目添加一个密钥,将其标记为来自本地数据库

签名:

export declare function markAsFromDataBase<T>(aValue: T): T;

Parameters

Parameter Type Description
aValue T the value to work with

返回:

T

a value with the marker

Home > @acoustic-content-sdk/redux-utils > removeArrayItemByAccessor

removeArrayItemByAccessor() function

Signature:

export declare function removeArrayItemByAccessor<T extends BaseAuthoringItem>(aAccessor: AccessorType, aItem: T, aUser?: User): Updater<T>;

Parameters

Parameter Type Description
aAccessor AccessorType
aItem T
aUser User

Returns:

Updater

主页 > @acoustic-content-sdk/redux-utils > removeDataBaseMarker

removeDataBaseMarker() function

从对象中删除数据库标记

签名:

export declare function removeDataBaseMarker<T>(aValue: T): T;

Parameters

Parameter Type Description
aValue T the value to work with

返回:

T

没有值the marker

Home > @acoustic-content-sdk/redux-utils > removeRecord

removeRecord() function

创建一个从记录中删除键的缩减器

签名:

export declare function removeRecord<T>(): RemoveRecordReducer<T>;

返回:

RemoveRecordReducer>

the reducer

Home > @acoustic-content-sdk/redux-utils > rxElementType

rxElementType() function

解析元素类型,直接来自元素或来自创作类型

签名:

export declare function rxElementType(aTypeResolver: UnaryFunction<string, Observable<AuthoringType>>, aLogSvc?: LoggerService, aScheduler?: SchedulerLike): UnaryFunction<AccessorType, OperatorFunction<RenderingContext, ELEMENT_TYPE>>;

Parameters

Parameter Type Description
aTypeResolver UnaryFunction&lt;string, Observable&lt;AuthoringType&gt;&gt;
aLogSvc LoggerService logger service
aScheduler SchedulerLike optional scheduler

返回:

UnaryFunction>

the resolved type or undefined if the type could not be determined

Home > @acoustic-content-sdk/redux-utils > rxLogDiff

rxLogDiff() function

Signature:

export declare function rxLogDiff<T>(aLogger: Logger): MonoTypeOperatorFunction<T>;

Parameters

Parameter Type Description
aLogger Logger

Returns:

MonoTypeOperatorFunction

主页 > @acoustic-content-sdk/redux-utils > rxResolveAuthoringItems

rxResolveAuthoringItems() function

解析项目和所有引用的项目和资产

签名:

export declare function rxResolveAuthoringItems(idOrItem: IdOrItem, resolveItem: ResolveAuthoringContentItem, resolveAsset: ResolveAuthoringAsset, aLogSvc?: LoggerService, scheduler?: SchedulerLike): Observable<ResolutionResult>;

Parameters

Parameter Type Description
idOrItem IdOrItem
resolveItem ResolveAuthoringContentItem callback to resolve a content item
resolveAsset ResolveAuthoringAsset callback to resolve an asset
aLogSvc LoggerService
scheduler SchedulerLike scheduler for recursive calls

返回:

ObservableResult code>

the observable containing the resolution result

Home > @acoustic-content-sdk/redux-utils > selectByDeliveryId

selectByDeliveryId() function

构造一个选择器,验证该 ID 是交付 ID(而非草稿 ID)并根据该 ID 从状态

Signature:

export declare function selectByDeliveryId<T>(aId?: string): UnaryFunction<Record<string, T>, T>;

Parameters

Parameter Type Description
aId string the ID

中进行选择返回:

UnaryFunction, T>

基于某些状态的该 ID 选择器

主页 > @acoustic-content-sdk/redux-utils > serializeDiff

serializeDiff() function

序列化两个JSON对象之间的差异

Signature:

export declare function serializeDiff(aOld: any, aNew: any, aSameStyle?: UnaryFunction<string, string>, aNewStyle?: UnaryFunction<string, string>, aDeletedStyle?: UnaryFunction<string, string>): string;

Parameters

Parameter Type Description
aOld any old object
aNew any new objects
aSameStyle UnaryFunction&lt;string, string&gt; styling callback for identical style
aNewStyle UnaryFunction&lt;string, string&gt; styling callback for new style
aDeletedStyle UnaryFunction&lt;string, string&gt; styling callback for deleted style

返回:

string

序列化后的字符串

&首页 @acoustic-content-sdk/redux-utils > sortAuthoringItems

sortAuthoringItems() function

对一组已解决的项目执行拓扑排序

签名:

export declare function sortAuthoringItems(aResult: ResolutionResult): AuthoringItem[];

Parameters

Parameter Type Description
aResult ResolutionResult the resolution result, basically a graph of nodes

返回:

AuthoringItem[]

the items in toplogical order, ie parents before children

Home > @acoustic-content-sdk/redux-utils > updateGenericProperties

updateGenericProperties() function

根据环境更新项目的属性

签名:

export declare function updateGenericProperties<T extends BaseAuthoringItem>(aItem: Updater<T>, aUser?: User): Updater<T>;

Parameters

Parameter Type Description
aItem Updater&lt;T&gt; updater for the item
aUser User optionally the current user

返回:

Updater< /code>

the updater after the item has been modified

Home > @acoustic-content-sdk/redux-utils > updateImageElement

updateImageElement() function

Signature:

export declare function updateImageElement(aAccessor: AccessorType, aItem: Updater<AuthoringContentItem>, aAsset: AuthoringAsset): Updater<AuthoringContentItem>;

Parameters

Parameter Type Description
aAccessor AccessorType
aItem Updater&lt;AuthoringContentItem&gt;
aAsset AuthoringAsset

Returns:

Updater

主页 > @acoustic-content-sdk/redux-utils > updateRecord

updateRecord() function

创建一个将项目添加到记录的

缩减程序签名:

export declare function updateRecord<T>(aKey: UnaryFunction<T, string>, aPredicate?: EqualsPredicate<T>): AddRecordReducer<T>;

Parameters

Parameter Type Description
aKey UnaryFunction&lt;T, string&gt; function to extract the key from the item
aPredicate EqualsPredicate&lt;T&gt; predicate to check if two items are equal

返回:

AddRecordReducer< /code>

the reducer

Home > @acoustic-content-sdk/redux-utils > updateSingleItem

updateSingleItem() function

Signature:

export declare function updateSingleItem<T>(aPredicate?: EqualsPredicate<T>): ItemReducer<T>;

Parameters

Parameter Type Description
aPredicate EqualsPredicate&lt;T&gt;

Returns:

ItemReducer

主页 > @acoustic-content-sdk/redux-utils > updateValueByAccessor

updateValueByAccessor() function

根据访问器表达式更新单个属性。

签名:

export declare function updateValueByAccessor<T extends BaseAuthoringItem>(aAccessor: AccessorType, aValue: any, aItem: T, aUser?: User): Updater<T>;

Parameters

Parameter Type Description
aAccessor AccessorType the accessor expression that points
aValue any the new value
aItem T the item to update
aUser User

返回:

Updater

具有修改值的项目的副本

主页 > @acoustic-content-sdk/redux-utils > ItemWithId

ItemWithId interface

Signature:

export interface ItemWithId 

Properties

Property Type Description
id string

Home > ; @acoustic-content-sdk/redux-utils > ItemWithLinkedDocId

ItemWithLinkedDocId interface

Signature:

export interface ItemWithLinkedDocId 

Properties

Property Type Description
id string
linkedDocId string

Home > ; @acoustic-content-sdk/redux-utils > ItemWithRevision

ItemWithRevision interface

Signature:

export interface ItemWithRevision extends ItemWithId 

Properties

Property Type Description
rev string

Home > ; @acoustic-content-sdk/redux-utils > NavigationJson

Signature:

export interface NavigationJson 

Properties

Property Type Description
children NavigationJson[]
id string

Home > ; @acoustic-content-sdk/redux-utils > NavSelectors

Interface that exposes selectors to the navigation structure

Signature:

export interface NavSelectors 

Properties

Property Type Description
root string ID of the (virtual) root item of the navigation
selectChildren UnaryFunction&lt;string, Observable&lt;string[]&gt;&gt; Selects the children of a particular item
selectParent UnaryFunction&lt;string, Observable&lt;string&gt;&gt; Selects the parent of a particular item

首页 > @acoustic-content-sdk/redux-utils > ResolvedNode

ResolvedNode interface

Signature:

export interface ResolvedNode<T> 

Properties

Property Type Description
id string
item T
parentId string

Home > ; @acoustic-content-sdk/redux-utils > Updater

Updater interface

为 json 对象提供修改功能的外观。 不会修改原始 JSON 对象,修改后的对象只会包含最少的修改次数。

Signature:

export interface Updater<T> 

Properties

Property Type Description
add BiFunction&lt;string, any, T&gt; Inserts a new value into an array pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.Pass undefined as the new value to delete the value.Returns the modified version of the top level object.
del UnaryFunction&lt;string, T&gt; Removes the value pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.Returns the modified version of the top level object.
get Generator&lt;T&gt; Returns the top level, modified object
set BiFunction&lt;string, any, T&gt; Replaces the value pointed to by the accessor with a new value. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.Pass undefined as the new value to delete the value.Returns the modified version of the top level object.

Home > @acoustic-content-sdk/redux-utils > addToSetEpic

addToSetEpic variable

构造一个将ADD 操作转换为SET 操作的史诗

签名:

addToSetEpic: <T>(aAddAction: string, aSetAction: string) => Epic<any, any, any, any>

<一个名字="_e9c7053186f123bb1423ee80e91cf8c07c351b0ed72d06b6fcf937c9eec6b2f8">

@acoustic-content-sdk/redux-utils > cloneAuthoringItems Basically

cloneAuthoringItems variable

a re-export of the clone functionality to have it all clean inside this one function

Signature:

cloneAuthoringItems: UnaryFunction<AuthoringItem[], AuthoringItem[]>

< /a>

首页 > @acoustic-content-sdk/redux-utils > DB_KEY

DB_KEY variable

Signature:

DB_KEY = "ecec4405-7fb1-4b86-8d27-7338eea45683"

Home > ; @acoustic-content-sdk/redux-utils > DB_VALUE

DB_VALUE variable

Signature:

DB_VALUE = "e3257dbc-1ca8-4d57-94a2-37934960f39f"

Home > ; @acoustic-content-sdk/redux-utils > ensureDraftId

ensureDraftId variable

Makes sure to end the ID with a draft suffix

Signature:

ensureDraftId: (aAuthoringId: string) => string

主页 > @acoustic-content-sdk/redux-utils > getDeliveryId

getDeliveryId variable

Returns the delivery ID from an authoring ID, ie strips off the ':draft' suffix from the ID

Signature:

getDeliveryId: UnaryFunction<string, string>

首页 > @acoustic-content-sdk/redux-utils > getDeliveryIdFromAuthoringItem

getDeliveryIdFromAuthoringItem variable

从创作项目返回交付 ID。

Signature:

getDeliveryIdFromAuthoringItem: UnaryFunction<ItemWithLinkedDocId | BaseAuthoringItem, string>

Home > @acoustic-content-sdk/redux-utils > getValueByAccessor

getValueByAccessor variable

Retrieves a property value by accessor

Signature:

getValueByAccessor: <T>(aItem: BaseAuthoringItem, aAccessor: string) => T

首页 > @acoustic-content-sdk/redux-utils > keyById

keyById variable

Extract the delivery ID of the draft

Signature:

keyById: UnaryFunction<ItemWithLinkedDocId, string>

首页 > @acoustic-content-sdk/redux-utils > ROOT_ID

ROOT_ID variable

Signature:

ROOT_ID: string

Home > ; @acoustic-content-sdk/redux-utils > selectClassification

selectClassification variable

Extracts the classification property

Signature:

selectClassification: UnaryFunction<BaseAuthoringItem | ContentItem, string>

Home< /a> > @acoustic-content-sdk/redux-utils > updateItemsWithRevision

updateItemsWithRevision variable

Signature:

updateItemsWithRevision: <T extends ItemWithRevision>(aState: Record<string, T>, aItem: T) => Record<string, T>

Home > ; @acoustic-content-sdk/redux-utils > AddRecordReducer

AddRecordReducer type

Reducer function that adds an item to a record

Signature:

export declare type AddRecordReducer<T> = BiFunction<Record<string, T>, T, Record<string, T>>;

主页 > @acoustic-content-sdk/redux-utils > AuthoringItem

AuthoringItem type

Signature:

export declare type AuthoringItem = AuthoringContentItem | AuthoringAsset;

Home > ; @acoustic-content-sdk/redux-utils > ItemReducer

ItemReducer type

Reducer function that updates an item

Signature:

export declare type ItemReducer<T> = BiFunction<T, T, T>;

首页 > @acoustic-content-sdk/redux-utils > RemoveRecordReducer

RemoveRecordReducer type

Reducer function that adds an item to a record

Signature:

export declare type RemoveRecordReducer<T> = BiFunction<Record<string, T>, string, Record<string, T>>;

主页 > @acoustic-content-sdk/redux-utils > ResolutionResult

ResolutionResult type

Signature:

export declare type ResolutionResult = Record<string, ResolvedNode<AuthoringItem>>;

Home > ; @acoustic-content-sdk/redux-utils > ResolveAuthoringAsset

ResolveAuthoringAsset type

Signature:

export declare type ResolveAuthoringAsset = UnaryFunction<string, Observable<AuthoringAsset>>;

Home > ; @acoustic-content-sdk/redux-utils > ResolveAuthoringContentItem

ResolveAuthoringContentItem type

Signature:

export declare type ResolveAuthoringContentItem = UnaryFunction<string, Observable<AuthoringContentItem>>;

Home > ; @acoustic-content-sdk/redux-utils > ItemWithId > id

ItemWithId.id property

Signature:

id?: string;

Home > ; @acoustic-content-sdk/redux-utils > NavigationJson > children

Signature:

children?: NavigationJson[];

Home > ; @acoustic-content-sdk/redux-utils > NavigationJson > id

Signature:

id: string;

Home > ; @acoustic-content-sdk/redux-utils > ItemWithRevision > rev

ItemWithRevision.rev property

Signature:

rev?: string;

Home > ; @acoustic-content-sdk/redux-utils > ItemWithLinkedDocId > id

ItemWithLinkedDocId.id property

Signature:

readonly id?: string;

Home > ; @acoustic-content-sdk/redux-utils > ItemWithLinkedDocId > linkedDocId

ItemWithLinkedDocId.linkedDocId property

Signature:

readonly linkedDocId?: string;

Home > ; @acoustic-content-sdk/redux-utils > 解析节点 > id

ResolvedNode.id property

Signature:

id: string;

Home > ; @acoustic-content-sdk/redux-utils > 解析节点 > item

ResolvedNode.item property

Signature:

item: T;

Home > ; @acoustic-content-sdk/redux-utils > 解析节点 > parentId

ResolvedNode.parentId property

Signature:

parentId?: string;

Home > ; @acoustic-content-sdk/redux-utils > 导航选择器 > root

ID of the (virtual) root item of the navigation

Signature:

root: string;

主页 > @acoustic-content-sdk/redux-utils > 导航选择器 > selectChildren

Selects the children of a particular item

Signature:

selectChildren: UnaryFunction<string, Observable<string[]>>;

首页 > @acoustic-content-sdk/redux-utils > 导航选择器 > selectParent

Selects the parent of a particular item

Signature:

selectParent: UnaryFunction<string, Observable<string>>;

Home > @acoustic-content-sdk/redux-utils > Updater > add

Updater.add property

Inserts a new value into an array pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.

Pass undefined as the new value to delete the value.

Returns the modified version of the top level object.

Signature:

add: BiFunction<string, any, T>;

Home > @acoustic-content-sdk/redux-utils > Updater > del

Updater.del property

Removes the value pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.

Returns the modified version of the top level object.

Signature:

del: UnaryFunction<string, T>;

Home > @acoustic-content-sdk/redux-utils > Updater > get

Updater.get property

Returns the top level, modified object

Signature:

get: Generator<T>;

Home > @acoustic-content-sdk/redux-utils > Updater > set

Updater.set property

Replaces the value pointed to by the accessor with a new value. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.

Pass undefined as the new value to delete the value.

Returns the modified version of the top level object.

签名:

set: BiFunction<string, any, T>;

npm

Implementation of utility functions that help working with redux state.

Immutability

One of the core principals of the redux pattern is to keep all state immutable. This implies that when updating a value we need to make a copy of the affected objects. The following functions help to limit the size of these copies.

Updater

The createUpdater creates an wrapper around an object. This wrapper allows to set or remove (deep) properties of the wrapped object without mutating it. The updater makes sure to only create the minimum set of shallow copies.

Example:

const myObject={...};
const updater = createUpdater(myObject);

updater.set('elements.text.value', 'newValue');

const newObject = updater.get();

The updater works similar to immer but without the overhead.

Invariance Checks

During development it is important to verify that objects are not getting mutated. Use the invariance checker to test this, but make sure to not include these checks in production builds for performance reasons.

Example:

const inv = invarianceChecker(myObject);
// do some operations

// validate that myObject has not been mutated
assert(inv());

API Documentation

API Documentation

Home > @acoustic-content-sdk/redux-utils

redux-utils package

Implementation of utility functions that help working with redux state.

Functions

Function Description
createBreadcrumb(aId, aSelParent, aSelId) Constructs a breadcrumb trail starting at a particular ID
createUpdater(aValue, aLogSvc) Constructs a function that updates one or more values in a json object.
equalsByRevision(aLeft, aRight)
getNavSelectors(aJson$, aLogSvc) Returns selectors that access parent and child nodes from a navigation structure
invarianceChecker(aValue) Creates a function that validates that an object has not changed. Note that this should only be used for debugging purposes, since it makes a deep copy of the value to test for the invariance
isDraftId(aAuthoringId) Tests if the authoring ID has a draft suffix
isNotFromDataBase(aValue) Tests if a value is not from a database
isNotRoot(aId)
markAsFromDataBase(aValue) Adds a key to the item marking it as coming from the local data base
removeArrayItemByAccessor(aAccessor, aItem, aUser)
removeDataBaseMarker(aValue) Removes the database marker from the object
removeRecord() Creates a reducer that removes a key from a record
rxElementType(aTypeResolver, aLogSvc, aScheduler) Resolves the element type, either directly from the element or from the authoring type
rxLogDiff(aLogger)
rxResolveAuthoringItems(idOrItem, resolveItem, resolveAsset, aLogSvc, scheduler) Resolves the item and all referenced items and assets
selectByDeliveryId(aId) Constructs a selector that validates that the ID is a delivery ID (not a draft ID) and selects based on that ID from the state
serializeDiff(aOld, aNew, aSameStyle, aNewStyle, aDeletedStyle) Serializes the differences between two JSON objects
sortAuthoringItems(aResult) Performs a topological sort on a set of resolved items
updateGenericProperties(aItem, aUser) Updates properties of the item that depend on the environment
updateImageElement(aAccessor, aItem, aAsset)
updateRecord(aKey, aPredicate) Creates a reducer that adds an item to a record
updateSingleItem(aPredicate)
updateValueByAccessor(aAccessor, aValue, aItem, aUser) Updates a single property based on the accessor expression.

Interfaces

Interface Description
ItemWithId
ItemWithLinkedDocId
ItemWithRevision
NavigationJson
NavSelectors Interface that exposes selectors to the navigation structure
ResolvedNode
Updater Facade that offers the modification functions for a json object. The original JSON object will not be modified and the modified object will only contain the minimum number of modifications.

Variables

Variable Description
addToSetEpic Constructs an epic that convers an ADD action to a SET action
cloneAuthoringItems Basically a re-export of the clone functionality to have it all clean inside this one function
DB_KEY
DB_VALUE
ensureDraftId Makes sure to end the ID with a draft suffix
getDeliveryId Returns the delivery ID from an authoring ID, i.e. strips off the ':draft' suffix from the ID
getDeliveryIdFromAuthoringItem Returns the delivery ID from an authoring item.
getValueByAccessor Retrieves a property value by accessor
keyById Extract the delivery ID of the draft
ROOT_ID
selectClassification Extracts the classification property
updateItemsWithRevision

Type Aliases

Type Alias Description
AddRecordReducer Reducer function that adds an item to a record
AuthoringItem
ItemReducer Reducer function that updates an item
RemoveRecordReducer Reducer function that adds an item to a record
ResolutionResult
ResolveAuthoringAsset
ResolveAuthoringContentItem

Home > @acoustic-content-sdk/redux-utils > createBreadcrumb

createBreadcrumb() function

Constructs a breadcrumb trail starting at a particular ID

Signature:

export declare function createBreadcrumb<T>(aId: string, aSelParent: UnaryFunction<string, Observable<T>>, aSelId: UnaryFunction<T, string>): Observable<T[]>;

Parameters

Parameter Type Description
aId string the start ID
aSelParent UnaryFunction&lt;string, Observable&lt;T&gt;&gt; selector function for the parent node
aSelId UnaryFunction&lt;T, string&gt; selector function for the ID from a parent node

Returns:

Observable<T[]>

the breadcrumb trail

Home > @acoustic-content-sdk/redux-utils > createUpdater

createUpdater() function

Constructs a function that updates one or more values in a json object.

Signature:

export declare function createUpdater<T>(aValue: T, aLogSvc?: LoggerService): Updater<T>;

Parameters

Parameter Type Description
aValue T the JSON structure to update
aLogSvc LoggerService

Returns:

Updater<T>

updater functions

Home > @acoustic-content-sdk/redux-utils > equalsByRevision

equalsByRevision() function

Signature:

export declare function equalsByRevision(aLeft: ItemWithRevision, aRight: ItemWithRevision): boolean;

Parameters

Parameter Type Description
aLeft ItemWithRevision
aRight ItemWithRevision

Returns:

boolean

Home > @acoustic-content-sdk/redux-utils > getNavSelectors

getNavSelectors() function

Returns selectors that access parent and child nodes from a navigation structure

Signature:

export declare function getNavSelectors(aJson$: Observable<NavigationJson>, aLogSvc?: LoggerService): NavSelectors;

Parameters

Parameter Type Description
aJson$ Observable&lt;NavigationJson&gt; the JSON that represents the navigation
aLogSvc LoggerService optional logger service

Returns:

NavSelectors

the selectors

Home > @acoustic-content-sdk/redux-utils > invarianceChecker

invarianceChecker() function

Creates a function that validates that an object has not changed. Note that this should only be used for debugging purposes, since it makes a deep copy of the value to test for the invariance

Signature:

export declare function invarianceChecker(aValue: any): Generator<boolean>;

Parameters

Parameter Type Description
aValue any the value to test

Returns:

Generator<boolean>

the validator

Home > @acoustic-content-sdk/redux-utils > isDraftId

isDraftId() function

Tests if the authoring ID has a draft suffix

Signature:

export declare function isDraftId(aAuthoringId: string): boolean;

Parameters

Parameter Type Description
aAuthoringId string the ID

Returns:

boolean

true if we have a draft suffix, else false

Home > @acoustic-content-sdk/redux-utils > isNotFromDataBase

isNotFromDataBase() function

Tests if a value is not from a database

Signature:

export declare function isNotFromDataBase(aValue: any): boolean;

Parameters

Parameter Type Description
aValue any the value

Returns:

boolean

true if the value exists and if it is not from the database, else false

Home > @acoustic-content-sdk/redux-utils > isNotRoot

isNotRoot() function

Signature:

export declare function isNotRoot(aId: string): boolean;

Parameters

Parameter Type Description
aId string

Returns:

boolean

Home > @acoustic-content-sdk/redux-utils > markAsFromDataBase

markAsFromDataBase() function

Adds a key to the item marking it as coming from the local data base

Signature:

export declare function markAsFromDataBase<T>(aValue: T): T;

Parameters

Parameter Type Description
aValue T the value to work with

Returns:

T

a value with the marker

Home > @acoustic-content-sdk/redux-utils > removeArrayItemByAccessor

removeArrayItemByAccessor() function

Signature:

export declare function removeArrayItemByAccessor<T extends BaseAuthoringItem>(aAccessor: AccessorType, aItem: T, aUser?: User): Updater<T>;

Parameters

Parameter Type Description
aAccessor AccessorType
aItem T
aUser User

Returns:

Updater<T>

Home > @acoustic-content-sdk/redux-utils > removeDataBaseMarker

removeDataBaseMarker() function

Removes the database marker from the object

Signature:

export declare function removeDataBaseMarker<T>(aValue: T): T;

Parameters

Parameter Type Description
aValue T the value to work with

Returns:

T

a value without the marker

Home > @acoustic-content-sdk/redux-utils > removeRecord

removeRecord() function

Creates a reducer that removes a key from a record

Signature:

export declare function removeRecord<T>(): RemoveRecordReducer<T>;

Returns:

RemoveRecordReducer<T>

the reducer

Home > @acoustic-content-sdk/redux-utils > rxElementType

rxElementType() function

Resolves the element type, either directly from the element or from the authoring type

Signature:

export declare function rxElementType(aTypeResolver: UnaryFunction<string, Observable<AuthoringType>>, aLogSvc?: LoggerService, aScheduler?: SchedulerLike): UnaryFunction<AccessorType, OperatorFunction<RenderingContext, ELEMENT_TYPE>>;

Parameters

Parameter Type Description
aTypeResolver UnaryFunction&lt;string, Observable&lt;AuthoringType&gt;&gt;
aLogSvc LoggerService logger service
aScheduler SchedulerLike optional scheduler

Returns:

UnaryFunction<AccessorType, OperatorFunction<RenderingContext, ELEMENT_TYPE>>

the resolved type or undefined if the type could not be determined

Home > @acoustic-content-sdk/redux-utils > rxLogDiff

rxLogDiff() function

Signature:

export declare function rxLogDiff<T>(aLogger: Logger): MonoTypeOperatorFunction<T>;

Parameters

Parameter Type Description
aLogger Logger

Returns:

MonoTypeOperatorFunction<T>

Home > @acoustic-content-sdk/redux-utils > rxResolveAuthoringItems

rxResolveAuthoringItems() function

Resolves the item and all referenced items and assets

Signature:

export declare function rxResolveAuthoringItems(idOrItem: IdOrItem, resolveItem: ResolveAuthoringContentItem, resolveAsset: ResolveAuthoringAsset, aLogSvc?: LoggerService, scheduler?: SchedulerLike): Observable<ResolutionResult>;

Parameters

Parameter Type Description
idOrItem IdOrItem
resolveItem ResolveAuthoringContentItem callback to resolve a content item
resolveAsset ResolveAuthoringAsset callback to resolve an asset
aLogSvc LoggerService
scheduler SchedulerLike scheduler for recursive calls

Returns:

Observable<ResolutionResult>

the observable containing the resolution result

Home > @acoustic-content-sdk/redux-utils > selectByDeliveryId

selectByDeliveryId() function

Constructs a selector that validates that the ID is a delivery ID (not a draft ID) and selects based on that ID from the state

Signature:

export declare function selectByDeliveryId<T>(aId?: string): UnaryFunction<Record<string, T>, T>;

Parameters

Parameter Type Description
aId string the ID

Returns:

UnaryFunction<Record<string, T>, T>

a selector for that ID based on some state

Home > @acoustic-content-sdk/redux-utils > serializeDiff

serializeDiff() function

Serializes the differences between two JSON objects

Signature:

export declare function serializeDiff(aOld: any, aNew: any, aSameStyle?: UnaryFunction<string, string>, aNewStyle?: UnaryFunction<string, string>, aDeletedStyle?: UnaryFunction<string, string>): string;

Parameters

Parameter Type Description
aOld any old object
aNew any new objects
aSameStyle UnaryFunction&lt;string, string&gt; styling callback for identical style
aNewStyle UnaryFunction&lt;string, string&gt; styling callback for new style
aDeletedStyle UnaryFunction&lt;string, string&gt; styling callback for deleted style

Returns:

string

the serialized string

Home > @acoustic-content-sdk/redux-utils > sortAuthoringItems

sortAuthoringItems() function

Performs a topological sort on a set of resolved items

Signature:

export declare function sortAuthoringItems(aResult: ResolutionResult): AuthoringItem[];

Parameters

Parameter Type Description
aResult ResolutionResult the resolution result, basically a graph of nodes

Returns:

AuthoringItem[]

the items in toplogical order, i.e. parents before children

Home > @acoustic-content-sdk/redux-utils > updateGenericProperties

updateGenericProperties() function

Updates properties of the item that depend on the environment

Signature:

export declare function updateGenericProperties<T extends BaseAuthoringItem>(aItem: Updater<T>, aUser?: User): Updater<T>;

Parameters

Parameter Type Description
aItem Updater&lt;T&gt; updater for the item
aUser User optionally the current user

Returns:

Updater<T>

the updater after the item has been modified

Home > @acoustic-content-sdk/redux-utils > updateImageElement

updateImageElement() function

Signature:

export declare function updateImageElement(aAccessor: AccessorType, aItem: Updater<AuthoringContentItem>, aAsset: AuthoringAsset): Updater<AuthoringContentItem>;

Parameters

Parameter Type Description
aAccessor AccessorType
aItem Updater&lt;AuthoringContentItem&gt;
aAsset AuthoringAsset

Returns:

Updater<AuthoringContentItem>

Home > @acoustic-content-sdk/redux-utils > updateRecord

updateRecord() function

Creates a reducer that adds an item to a record

Signature:

export declare function updateRecord<T>(aKey: UnaryFunction<T, string>, aPredicate?: EqualsPredicate<T>): AddRecordReducer<T>;

Parameters

Parameter Type Description
aKey UnaryFunction&lt;T, string&gt; function to extract the key from the item
aPredicate EqualsPredicate&lt;T&gt; predicate to check if two items are equal

Returns:

AddRecordReducer<T>

the reducer

Home > @acoustic-content-sdk/redux-utils > updateSingleItem

updateSingleItem() function

Signature:

export declare function updateSingleItem<T>(aPredicate?: EqualsPredicate<T>): ItemReducer<T>;

Parameters

Parameter Type Description
aPredicate EqualsPredicate&lt;T&gt;

Returns:

ItemReducer<T>

Home > @acoustic-content-sdk/redux-utils > updateValueByAccessor

updateValueByAccessor() function

Updates a single property based on the accessor expression.

Signature:

export declare function updateValueByAccessor<T extends BaseAuthoringItem>(aAccessor: AccessorType, aValue: any, aItem: T, aUser?: User): Updater<T>;

Parameters

Parameter Type Description
aAccessor AccessorType the accessor expression that points
aValue any the new value
aItem T the item to update
aUser User

Returns:

Updater<T>

a copy of the item with the modified value

Home > @acoustic-content-sdk/redux-utils > ItemWithId

ItemWithId interface

Signature:

export interface ItemWithId 

Properties

Property Type Description
id string

Home > @acoustic-content-sdk/redux-utils > ItemWithLinkedDocId

ItemWithLinkedDocId interface

Signature:

export interface ItemWithLinkedDocId 

Properties

Property Type Description
id string
linkedDocId string

Home > @acoustic-content-sdk/redux-utils > ItemWithRevision

ItemWithRevision interface

Signature:

export interface ItemWithRevision extends ItemWithId 

Properties

Property Type Description
rev string

Home > @acoustic-content-sdk/redux-utils > NavigationJson

Signature:

export interface NavigationJson 

Properties

Property Type Description
children NavigationJson[]
id string

Home > @acoustic-content-sdk/redux-utils > NavSelectors

Interface that exposes selectors to the navigation structure

Signature:

export interface NavSelectors 

Properties

Property Type Description
root string ID of the (virtual) root item of the navigation
selectChildren UnaryFunction&lt;string, Observable&lt;string[]&gt;&gt; Selects the children of a particular item
selectParent UnaryFunction&lt;string, Observable&lt;string&gt;&gt; Selects the parent of a particular item

Home > @acoustic-content-sdk/redux-utils > ResolvedNode

ResolvedNode interface

Signature:

export interface ResolvedNode<T> 

Properties

Property Type Description
id string
item T
parentId string

Home > @acoustic-content-sdk/redux-utils > Updater

Updater interface

Facade that offers the modification functions for a json object. The original JSON object will not be modified and the modified object will only contain the minimum number of modifications.

Signature:

export interface Updater<T> 

Properties

Property Type Description
add BiFunction&lt;string, any, T&gt; Inserts a new value into an array pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.Pass undefined as the new value to delete the value.Returns the modified version of the top level object.
del UnaryFunction&lt;string, T&gt; Removes the value pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.Returns the modified version of the top level object.
get Generator&lt;T&gt; Returns the top level, modified object
set BiFunction&lt;string, any, T&gt; Replaces the value pointed to by the accessor with a new value. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.Pass undefined as the new value to delete the value.Returns the modified version of the top level object.

Home > @acoustic-content-sdk/redux-utils > addToSetEpic

addToSetEpic variable

Constructs an epic that convers an ADD action to a SET action

Signature:

addToSetEpic: <T>(aAddAction: string, aSetAction: string) => Epic<any, any, any, any>

Home > @acoustic-content-sdk/redux-utils > cloneAuthoringItems

cloneAuthoringItems variable

Basically a re-export of the clone functionality to have it all clean inside this one function

Signature:

cloneAuthoringItems: UnaryFunction<AuthoringItem[], AuthoringItem[]>

Home > @acoustic-content-sdk/redux-utils > DB_KEY

DB_KEY variable

Signature:

DB_KEY = "ecec4405-7fb1-4b86-8d27-7338eea45683"

Home > @acoustic-content-sdk/redux-utils > DB_VALUE

DB_VALUE variable

Signature:

DB_VALUE = "e3257dbc-1ca8-4d57-94a2-37934960f39f"

Home > @acoustic-content-sdk/redux-utils > ensureDraftId

ensureDraftId variable

Makes sure to end the ID with a draft suffix

Signature:

ensureDraftId: (aAuthoringId: string) => string

Home > @acoustic-content-sdk/redux-utils > getDeliveryId

getDeliveryId variable

Returns the delivery ID from an authoring ID, i.e. strips off the ':draft' suffix from the ID

Signature:

getDeliveryId: UnaryFunction<string, string>

Home > @acoustic-content-sdk/redux-utils > getDeliveryIdFromAuthoringItem

getDeliveryIdFromAuthoringItem variable

Returns the delivery ID from an authoring item.

Signature:

getDeliveryIdFromAuthoringItem: UnaryFunction<ItemWithLinkedDocId | BaseAuthoringItem, string>

Home > @acoustic-content-sdk/redux-utils > getValueByAccessor

getValueByAccessor variable

Retrieves a property value by accessor

Signature:

getValueByAccessor: <T>(aItem: BaseAuthoringItem, aAccessor: string) => T

Home > @acoustic-content-sdk/redux-utils > keyById

keyById variable

Extract the delivery ID of the draft

Signature:

keyById: UnaryFunction<ItemWithLinkedDocId, string>

Home > @acoustic-content-sdk/redux-utils > ROOT_ID

ROOT_ID variable

Signature:

ROOT_ID: string

Home > @acoustic-content-sdk/redux-utils > selectClassification

selectClassification variable

Extracts the classification property

Signature:

selectClassification: UnaryFunction<BaseAuthoringItem | ContentItem, string>

Home > @acoustic-content-sdk/redux-utils > updateItemsWithRevision

updateItemsWithRevision variable

Signature:

updateItemsWithRevision: <T extends ItemWithRevision>(aState: Record<string, T>, aItem: T) => Record<string, T>

Home > @acoustic-content-sdk/redux-utils > AddRecordReducer

AddRecordReducer type

Reducer function that adds an item to a record

Signature:

export declare type AddRecordReducer<T> = BiFunction<Record<string, T>, T, Record<string, T>>;

Home > @acoustic-content-sdk/redux-utils > AuthoringItem

AuthoringItem type

Signature:

export declare type AuthoringItem = AuthoringContentItem | AuthoringAsset;

Home > @acoustic-content-sdk/redux-utils > ItemReducer

ItemReducer type

Reducer function that updates an item

Signature:

export declare type ItemReducer<T> = BiFunction<T, T, T>;

Home > @acoustic-content-sdk/redux-utils > RemoveRecordReducer

RemoveRecordReducer type

Reducer function that adds an item to a record

Signature:

export declare type RemoveRecordReducer<T> = BiFunction<Record<string, T>, string, Record<string, T>>;

Home > @acoustic-content-sdk/redux-utils > ResolutionResult

ResolutionResult type

Signature:

export declare type ResolutionResult = Record<string, ResolvedNode<AuthoringItem>>;

Home > @acoustic-content-sdk/redux-utils > ResolveAuthoringAsset

ResolveAuthoringAsset type

Signature:

export declare type ResolveAuthoringAsset = UnaryFunction<string, Observable<AuthoringAsset>>;

Home > @acoustic-content-sdk/redux-utils > ResolveAuthoringContentItem

ResolveAuthoringContentItem type

Signature:

export declare type ResolveAuthoringContentItem = UnaryFunction<string, Observable<AuthoringContentItem>>;

Home > @acoustic-content-sdk/redux-utils > ItemWithId > id

ItemWithId.id property

Signature:

id?: string;

Home > @acoustic-content-sdk/redux-utils > NavigationJson > children

Signature:

children?: NavigationJson[];

Home > @acoustic-content-sdk/redux-utils > NavigationJson > id

Signature:

id: string;

Home > @acoustic-content-sdk/redux-utils > ItemWithRevision > rev

ItemWithRevision.rev property

Signature:

rev?: string;

Home > @acoustic-content-sdk/redux-utils > ItemWithLinkedDocId > id

ItemWithLinkedDocId.id property

Signature:

readonly id?: string;

Home > @acoustic-content-sdk/redux-utils > ItemWithLinkedDocId > linkedDocId

ItemWithLinkedDocId.linkedDocId property

Signature:

readonly linkedDocId?: string;

Home > @acoustic-content-sdk/redux-utils > ResolvedNode > id

ResolvedNode.id property

Signature:

id: string;

Home > @acoustic-content-sdk/redux-utils > ResolvedNode > item

ResolvedNode.item property

Signature:

item: T;

Home > @acoustic-content-sdk/redux-utils > ResolvedNode > parentId

ResolvedNode.parentId property

Signature:

parentId?: string;

Home > @acoustic-content-sdk/redux-utils > NavSelectors > root

ID of the (virtual) root item of the navigation

Signature:

root: string;

Home > @acoustic-content-sdk/redux-utils > NavSelectors > selectChildren

Selects the children of a particular item

Signature:

selectChildren: UnaryFunction<string, Observable<string[]>>;

Home > @acoustic-content-sdk/redux-utils > NavSelectors > selectParent

Selects the parent of a particular item

Signature:

selectParent: UnaryFunction<string, Observable<string>>;

Home > @acoustic-content-sdk/redux-utils > Updater > add

Updater.add property

Inserts a new value into an array pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.

Pass undefined as the new value to delete the value.

Returns the modified version of the top level object.

Signature:

add: BiFunction<string, any, T>;

Home > @acoustic-content-sdk/redux-utils > Updater > del

Updater.del property

Removes the value pointed to by the accessor. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.

Returns the modified version of the top level object.

Signature:

del: UnaryFunction<string, T>;

Home > @acoustic-content-sdk/redux-utils > Updater > get

Updater.get property

Returns the top level, modified object

Signature:

get: Generator<T>;

Home > @acoustic-content-sdk/redux-utils > Updater > set

Updater.set property

Replaces the value pointed to by the accessor with a new value. All values across the parent path will be cloned (shallow) if they do not have a clone, yet.

Pass undefined as the new value to delete the value.

Returns the modified version of the top level object.

Signature:

set: BiFunction<string, any, T>;
更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文