Skip to content

English__Data Sources__Object

Ramirez Vargas, José Pablo edited this page Nov 7, 2024 · 2 revisions

Object Data Source

wj-config provides the Object data source that allows the developer to directly provide an object as configuration data source.

Despite being the simplest of data sources, is one of the most popular ones. It is by far the easiest one to use.

How To Use the Object Data Source

As with all other data sources, there is a specialized addObject() method in the configuration builder that assists with this job. This function defines one parameter in the form of 1 overload:

    addObject<NewT extends Record<string, any>>(obj: NewT | (() => Promise<NewT>)): IBuilder<MergeResult<T, NewT>>;
  1. The object to use as configuration data source, or a function that returns said object.

Just like other data sources, the main data argument may be passed directly, or a function that returns it may be used as well. This function approach is the recommended approach when doing any form of conditional configuration if obtaining the object will incur in potentially-wasted CPU cycles or RAM.

This data source provides the most flexibility for developers. The object can be the product of any algorithm. For example, it can be used to include objects that are the result of reading files.

To be perfectly honest, this is the only truly needed data source. All other data sources are just convenient data sources that provide shortcuts for popular tasks like JSON parsing or data fetching. Ok, granted, maybe the Dictionary data source is the one other "must-have" data source.

Data Requirements

The only requirement is that the provided object be a POJO-like object.