use/objectCalculated
Interfaces
ObjectCalculatedProperties
The properties for object calculated.
Properties
parentState
parentState:
object
The parent state.
crud
crud:
object
The crud handlers.
crud.args
args:
Reactive<{ } |TargetArgs>
The arguments to be passed to the crud handlers.
crud.create
create:
CrudCreateFn
The create function.
crud.delete
delete:
CrudDeleteFn
The delete function.
crud.executeAction
executeAction:
CrudObjectExecuteActionFn
The executeAction function.
crud.patch
patch:
CrudPatchFn
The patch function.
crud.retrieve
retrieve:
CrudRetrieveFn
The retrieve function.
crud.subscribe
subscribe:
CrudObjectSubscribeFn
The subscribe function.
crud.update
update:
CrudUpdateFn
The update function.
deleted
deleted:
boolean
Whether the object was deleted by the delete action or a subscription delete event. Cleared when a later create, retrieve, update, or patch repopulates the object, and by clear().
error
error:
Error
The error that occurred.
errored
errored:
boolean
Whether an error has occurred.
intendToRetrieve?
optionalintendToRetrieve?:boolean
Whether the object intends to retrieve.
intendToSubscribe?
optionalintendToSubscribe?:boolean
Whether the object intends to subscribe.
loading
loading:
boolean
Whether the component is loading.
object
object:
Reactive<CrudObject>
The object.
params
params:
object
The arguments to be passed to the retrieve function.
Index Signature
[key: string]: any
parentStateObjectWatchRunning?
optionalparentStateObjectWatchRunning?:boolean
Whether the parent state object watch is running.
pk
pk:
string
The pk of the object.
pkKey
pkKey:
string
The pk key of the object.
relatedObject?
optionalrelatedObject?:object
The related objects, by rule name. Each entry is backed by a computed, but it is read through a reactive proxy that unwraps it, so reads yield the related object (or array of related objects) and never carry a .value.
Index Signature
[rule: string]: any
relatedObjectRules?
optionalrelatedObjectRules?:ObjectRelatedRawRules
The rules for defining relationships for the managed object to other collections of objects.
relatedObjectWatchRunning?
optionalrelatedObjectWatchRunning?:boolean
Whether the related object watch is running.
relatedRunning?
optionalrelatedRunning?:boolean
Whether the related objects are loading.
running?
optionalrunning?:boolean
Whether the related objects are loading or the parent state is loading.
subscribed?
optionalsubscribed?:boolean
Whether the object is subscribed.
state
state:
object
The object calculated state.
calculatedObject
calculatedObject:
object
The calculated values, by rule name. Each entry is backed by a computed, but it is read through a reactive proxy that unwraps it, so reads yield the calculated value and never carry a .value.
Index Signature
[ruleKey: string]: any
calculatedObjectRules
calculatedObjectRules:
ObjectCalculatedRules
The calculated object rules.
calculatedObjectWatchRunning
calculatedObjectWatchRunning:
boolean
Whether the calculated object watch is running.
calculatedRunning
calculatedRunning:
boolean
Whether the calculated is running.
crud
crud:
object
The crud handlers.
crud.args
args:
Reactive<{ } |TargetArgs>
The arguments to be passed to the crud handlers.
crud.create
create:
CrudCreateFn
The create function.
crud.delete
delete:
CrudDeleteFn
The delete function.
crud.executeAction
executeAction:
CrudObjectExecuteActionFn
The executeAction function.
crud.patch
patch:
CrudPatchFn
The patch function.
crud.retrieve
retrieve:
CrudRetrieveFn
The retrieve function.
crud.subscribe
subscribe:
CrudObjectSubscribeFn
The subscribe function.
crud.update
update:
CrudUpdateFn
The update function.
deleted
deleted:
boolean
Whether the object was deleted by the delete action or a subscription delete event. Cleared when a later create, retrieve, update, or patch repopulates the object, and by clear().
error
error:
Error
The error that occurred.
errored
errored:
boolean
Whether an error has occurred.
intendToRetrieve?
optionalintendToRetrieve?:boolean
Whether the object intends to retrieve.
intendToSubscribe?
optionalintendToSubscribe?:boolean
Whether the object intends to subscribe.
loading
loading:
boolean
Whether the component is loading.
object
object:
Reactive<CrudObject>
The object.
params
params:
object
The arguments to be passed to the retrieve function.
Index Signature
[key: string]: any
parentStateObjectWatchRunning
parentStateObjectWatchRunning:
boolean
Whether the parent state object watch is running.
pk
pk:
string
The pk of the object.
pkKey
pkKey:
string
The pk key of the object.
relatedObject?
optionalrelatedObject?:object
The related objects, by rule name. Each entry is backed by a computed, but it is read through a reactive proxy that unwraps it, so reads yield the related object (or array of related objects) and never carry a .value.
Index Signature
[rule: string]: any
relatedObjectRules?
optionalrelatedObjectRules?:ObjectRelatedRawRules
The rules for defining relationships for the managed object to other collections of objects.
relatedObjectWatchRunning?
optionalrelatedObjectWatchRunning?:boolean
Whether the related object watch is running.
relatedRunning?
optionalrelatedRunning?:boolean
Whether the related objects are loading.
running
running:
boolean
Whether the related objects are loading or the parent state is loading.
subscribed?
optionalsubscribed?:boolean
Whether the object is subscribed.
stop
stop: () =>
void
Stops composition's effects and cleans up resources.
Returns
void
ObjectCalculatedRawProps
The consumer-supplied props for the object calculated composable, namely the calculated-object rules ref.
Properties
calculatedObjectRules
calculatedObjectRules:
Ref<ObjectCalculatedRules,ObjectCalculatedRules>
The calculated object rules.
ObjectCalculatedRawState
The raw state for object calculated.
Properties
calculatedObject
calculatedObject:
object
The calculated values, by rule name. Each entry is backed by a computed, but it is read through a reactive proxy that unwraps it, so reads yield the calculated value and never carry a .value.
Index Signature
[ruleKey: string]: any
calculatedObjectRules
calculatedObjectRules:
ObjectCalculatedRules
The calculated object rules.
calculatedObjectWatchRunning
calculatedObjectWatchRunning:
boolean
Whether the calculated object watch is running.
calculatedRunning
calculatedRunning:
boolean
Whether the calculated is running.
parentStateObjectWatchRunning
parentStateObjectWatchRunning:
boolean
Whether the parent state object watch is running.
running
running:
Ref<boolean,boolean>
Whether the object calculated is running.
Type Aliases
ObjectCalculated
ObjectCalculated =
ObjectCalculatedProperties
The object calculated instance.
Type Parameters
ObjectCalculatedOptions
ObjectCalculatedOptions =
object&ObjectCalculatedRawProps
The options used to create an object calculated instance (the parent state plus the calculated-object rules).
Type Declaration
parentState
parentState:
ObjectCalculatedParentState
Type Parameters
ObjectCalculatedParentRawState
ObjectCalculatedParentRawState =
ObjectInstanceRawState&Partial<ObjectSubscriptionRawState> &Partial<ObjectRelatedRawState>
The raw, pre-unwrapped parent state consumed by the object calculated mixin, aggregating the upstream object composable states.
Type Parameters
ObjectCalculatedParentState
ObjectCalculatedParentState =
UnwrapNestedRefs
The object calculated options.
Type Parameters
ObjectCalculatedRules
ObjectCalculatedRules =
object
Rules for calculating values from the managed object, keyed by rule name. Each rule is used as a computed body and receives exactly two arguments: the managed object and its related objects (the latter only populated when a useObjectRelated sits upstream).
Type Parameters
Index Signature
[ruleKey: string]: (object, relatedObject) => any
ObjectCalculatedState
ObjectCalculatedState =
UnwrapNestedRefs
The state for object calculated.
Type Parameters
Functions
useObjectCalculated()
useObjectCalculated(
options):ObjectCalculatedProperties
Vue Composition API composable function for object calculated.
Parameters
options
The object calculated options.
Returns
- The object calculated instance.
Example
<script setup>
import { useObjectCalculated, useObjectSubscription } from "@arrai-innovations/reactive-helpers";
import { reactive } from "vue";
const objectSubscriptionProps = reactive({
// whatever object subscription props you need to work with your crud implementation
target: {},
params: {},
pk: '1',
pkKey: 'id',
intendToRetrieve: true,
});
const objectSubscription = useObjectSubscription({ props: objectSubscriptionProps });
const objectCalculatedProps = reactive({
parentState: objectSubscription.state,
calculatedObjectRules: {
someRule: (object, relatedObject) => {
// some complex calculation. relatedObject holds the managed object's related objects, and is
// only populated when a useObjectRelated sits between the object and this composable.
// this is used as a computed body.
return object.someProperty + object.someOtherProperty;
},
// ...further rules
},
});
const objectCalculated = useObjectCalculated(objectCalculatedProps);
</script>
<template>
<div>
<!-- the reactive result of the calculation, based on the fn passed in, turned into a computed -->
<p>{{ objectCalculated.state.calculatedObject.someRule }}</p>
</div>
</template>useObjectCalculateds()
useObjectCalculateds(
objectCalculatedArgs):object
Helper function to create multiple object calculateds instances.
Parameters
objectCalculatedArgs
Options for each object calculated to create.
Returns
object
- The created object calculated instances by key.