Manages Roqueform field annotations.
npm install @roqueform/annotations-pluginManages Roqueform field annotations.
``sh`
npm install --save-prod @roqueform/annotations-plugin
š API documentation is available here.
Annotations allow to associate arbitrary data with fields.
`ts
import { createField } from 'roqueform';
import { annotationsPlugin } from '@roqueform/annotations-plugin';
const planetField = createField(
{ name: 'Pluto' },
annotationsPlugin({ isDisabled: false })
);
planetField.at('name').annotations.isDisabled // ā® false
`
Update annotations for a single field:
`ts
planetField.annotate({ isDisabled: true });
planetField.annotations.isDisabled // ā® true
planetField.at('name').annotations.isDisabled // ā® false
`
Annotate field and all of its children recursively:
`ts
planetField.annotate({ isDisabled: true }, { recursive: true });
planetField.annotations.isDisabled // ā® true
// š The child field was annotated along with its parent
planetField.at('name').annotations.isDisabled // ā® true
`
Annotations can be updated using a callback. This is especially useful in conjunction with recursive flag:
`ts`
planetField.annotate(
field => {
// Toggle disabled flag for the field and its children
return { isDisabled: !field.annotations.isDisabled };
},
{ recursive: true }
);
Subscribe to annotation changes:
`ts``
planetField.subscribe('change:annotations', event => {
event.target.annotations;
// ā® { isDisabled: boolean }
});