furo-data-object

furo-data-object #

@furo/data v2.18.0
import '@furo/data/src/furo-data-object.js';
exports FuroDataObject js
exports <furo-data-object> custom-element-definition
superclass LitElement

summary Typed data object

furo-data-object gives you a object which is built based on the type spec. The types must be available in the {Env}, learn more about setting up the environment in the guide.

The data will mostly be used in a [data-ui]/(../../data-input/doc) component or in component that yoh build, which contains one or more of them.

furo-data-object receives its data regularly from a collection-aget or a entity-aget. But you can also send json data which is formed like the raw-data of this type.

furo-data-object will not do any validation or data manipulation neither will send the data. It is just responsible to transform incomming data to an object and vice versa. You can access the manipulated data structure on the property .data.rawData with javascript (if needed).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 <!-- The furo-data-object will send a initial dataObject of type project.Project on at-response-ready -->
 <furo-data-object
     type="project.Project"
     fn-inject-raw="--response(*.data)" at-object-ready="--dataObject"></furo-data-object>

 <!-- The furo-entity-agent will fetch the data from ProjectService and pass it in at-response to the furo-data-object.  -->
 <furo-entity-agent
     service="ProjectService"
     fn-save="--saveClicked"
     fn-bind-request-data="--dataObject" at-response="--response" ></furo-entity-agent>

Attributes and Properties #

type #

type String

Set the type. The type must be available in the environment

json #

get the data from the data object as raw json

Events #

data-injected #

at-data-injected``

Fired when injected data was processed (bubbles).

data-changed #

at-data-changed{Object|CollectionNode}

Fired when data in furo-data-object has changed (bubbles). This event fires a lot, consider using a de-bounce with the event.

data-changed-after-inject #

at-data-changed-after-inject{Object|CollectionNode}

Fired when data in furo-data-object has changed after injectRaw is complete (bubbles). This event fires a lot, consider using a de-bounce with the event.

field-value-changed #

at-field-value-changed{Object} the field node

Fired when a field has changed.

validation-success #

at-validation-successDataObject

Fired when validation results in a valid state.

validation-failed #

at-validation-failedDataObject

Fired when validation results in a invalid state.

data-object-became-invalid #

at-data-object-became-invalid{Object|EntityNode} reference to entity

Fired when the data object switches from ininvalid to invalid state (bubbles).

data-object-became-valid #

at-data-object-became-valid{Object|EntityNode} reference to entity

Fired when the data object switches from invalid to valid state (bubbles).

object-ready #

at-object-readyA EntityNode object

Fired when the object defined by type is built (bubbles).

init-completed #

at-init-completedA EntityNode object

Fired when the object init was done (bubbles).

Methods #

injectRaw #

injectRaw(jsonObj `` ) ⟹ void

`` fn-inject-raw

inject a raw data response from the corresonding agent.

Input may look something like this:

Entity data

1
2
3
4
5
{
 "data": {},
 "links": [],
 "meta": {}
}

Collection data

1
2
3
4
5
6
{
 "data": {},
 "links": [],
 "meta": {},
 "entities": []
}
  • jsonObj

setPristine #

setPristine() ⟹ void

*fn-set-pristine

Set all nodes to pristine

Useful for working with deltas



clearAllErrors #

clearAllErrors() ⟹ void

*fn-clear-all-errors

Clears all errors on children without any validation!



validateAllFields #

validateAllFields() ⟹ void

*fn-validate-all-fields

Triggers the validation of all fields in the data object.

Use this before you submit some data to a server.

Will cause a data-object-became-valid or data-object-became-invalid and a validation-success or validation-failed event.



appendErrors #

appendErrors(grpcStatus `` ) ⟹ void

`` fn-append-errors

Append errors from custom methods or other agents or sources to the data object. The error object must have a grpc status error signature like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
 "code":3,
 "message":"invalid username",
 "details":[{
         "@type":"type.googleapis.com/google.rpc.BadRequest",
         "field_violations":[{
             "field":"user.name",
             "description":"The username must only contain alphanumeric characters"
          }]
    }]
}
  • grpcStatus

reset #

reset() ⟹ void

*fn-reset

Reset the model to the last injected state.

To set the model to the initial state use init



init #

init() ⟹ void

*fn-init

Sets the model to an initial state according to the given type.

fires init-completed

To reset changed data to the last injected state, please use reset();



getData #

getData() ⟹ void

*fn-get-data

get the data of the data object