Data Transformer Pluck

Edit on GitHub

This document explains the Data Transformer Pluck service in the Components Library.

Overview

Data Transformer Pluck is an Angular Service that selects and returns a nested object by path via configuration.

The datasource example below will return the value of the three key (‘123’) of the data input after receiving the response.

Service configuration:

  • path - the name of the property from which the value needs to be retrieved. The path may contain nested properties separated by dots, just like in Javascript.
<spy-select
    [datasource]="{
        type: 'inline',
        data: {
            one: {
                two: {
                    three: '123',  
                },
            },
        },
        transform: {
            type: 'pluck',
            path: 'one.two.three',
        },
    }"
>
</spy-select>

Service registration

Register the service:

@NgModule({
    imports: [
        DataTransformerModule.withTransformers({
            pluck: PluckDataTransformerService,
        }),
    ],
})
export class RootModule {}

Interfaces

Below you can find interfaces for the Data Transformer Pluck:

declare module '@spryker/data-transformer' {
    interface DataTransformerRegistry {
        pluck: PluckDataTransformerService;
    }
}

export interface PluckDataTransformerConfig extends DataTransformerConfig {
    path: string;
}