-
Notifications
You must be signed in to change notification settings - Fork 5
Using Zimlet Data
Zimlets can provide data to be consumed by the host application. A Zimlet can register, mutate and unregister data.
Zimlets can provide data to the host application by calling registerData on the 'plugins' reference you get from context.
- name: String, name identifier for the data.
- dataArray: Array of data to register.
plugins.registerData(name, dataArray)
Zimlets can mutate the data (provided in the registerData) by calling mutateData.
- name: String, name identifier for the data.
- mutator: Function, A function that will return a new list of the objects, the mutated objects.
plugins.mutateData(name, mutator)
Zimlets can unregister data by calling plugins.unregisterData() and pass the data name identifier.
- name: String, name identifier for the data.
plugins.unregisterData(name)
In this example, we demonstrate how a Zimlet can provide Contact fields and control its visibility.
- You first need to register the data by passing the 'contact::attributes' name identifier and an array of object that represent the fields you want to see in your Contacts.
The object defining the field should contain the following fields:
- fieldName: String, the name that will be displayed in the contact form.
- show: Boolean, true to display the field, false otherwise.
- decorator: Function, A function that will return a transformed version of the passed in value.
plugins.registerData('contact::attributes', [
{
fieldName: 'skype',
show: false,
decorator: skypeName => <a href={`skype://${skypeName}?Call`}>{skypeName}</a>
}
]);
For mutating the contact fields, provide a function that alters and return the list of fields. In this case, we modify the 'show' property of the field so it can be displayed.
plugins.mutateData('contact::attributes', fields => {
const listOfFields = !isEmpty(fields) && get(fields[0], 'data');
return (
!isEmpty(listOfFields) &&
listOfFields.map(field => {
field.show = true;
return field;
})
);
});
For unregistering the fields, call unregisterData and pass the name identifier.
plugins.unregisterData('contact::attributes');
- Home
- Client Tool
- Getting Started
- Creating Your Zimlet
- Zimlet Design Patterns
- Advanced