0.0.3 • Published 2 years ago

@j-a-z/config v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Config

A store-like tool that is designed to describe and organize the properties and parameters of an object, with the ability to subscribe to changes and specify media queries.

Basic example


With the Primitives package, you will be able to specify media queries for individual values, which will create a uniform system for all screen resolutions.

Basic example with primitives


Static properties

Config.shared

A Map object that contains all shared Config instances, indexed by their name

Config.projectConfiguration

A ProjectConfiguration object that represents the current project configuration. This can be set using the setProjectConfiguration method.

Config.events

An Events object that allows users to register listeners for various events that can be triggered by the Config class.

Example

Constructor

new Config(config: ConfigInitializationObject<T>, name?: string)

Constructs a new Config instance with the provided configuration object and optional name.

Public Properties

.name

The name of the Config instance. This can be set in the constructor.

.current

The current configuration object.

Public Methods

.ready()

Marks the Config instance as ready. This will trigger the resize event and add the Config instance to the shared Map if it has a name.

.destroy()

Destroys the Config instance. This will remove all subscribers, unregister the resize event listener, and remove the Config instance from the shared Map if it has a name.

.useSnapshot(snapshot)

Updates the Config instance with the values from the provided snapshot.

.createSnapshot()

Returns a string representation of the current Config instance in the form of a snapshot.

.subscribe(dottedKey, subscriber)

Subscribes the provided subscriber function to the specified keys in the Config instance. The subscriber will be notified whenever the value of the keys changes.

.unsubscribe(dottedKey, subscriber)

Unsubscribes the provided subscriber function from the specified keys in the Config instance.

.removeAllSubscribers()

Removes all subscribers from the Config instance.

.notifyAllSubscribers()

Notifies all subscribers of all keys in the Config instance's configuration object of the current values of the keys. This will trigger the subscriber functions to be called with the current values of the keys as arguments.

.reset()

Resets the Config instance to its original state. This will set all the values in the configuration object back to their original values, as specified in the config parameter of the constructor. Any subscribers registered for the keys will be notified of the changes.

.traverse(callback)

Traverses the Config instance's configuration object and calls the provided callback function for each key/value pair

.getPrimitiveProperty(key)

Returns the Primitive instance for the specified key in the provided object. If the key does not exist or the value is not a Primitive instance, the method will return undefined.

.setPrimitiveProperty(key, value, mediaQuery, changeDefaults)

Sets the value of the specified key in the provided object.

.createSnapshot()

Creates a snapshot of the provided Config instance. This can be used to save the current state of the Config instance and restore it later using the useSnapshot method

.useSnapshot(configSnapshotString)

Restores the Config instance to the state represented by the provided snapshot