modern-now

Back

Notes

Simple config

While it's possible to store every config attribute in one (ore many!) "data" attribute, it's not always practical for many reasons. All values end up being strings, it's a bit verbose and it's not exactly easy to set functions.

You could also use json directly, but again: it's verbose, and it requires your attributes to use single quotes (and breaks even more if you forget to escape single quotes within).

In order to make things simpler, you can also use "simple configs" which is a json like structure with key: value comma separated elements. Strings can be either single or double quoted.

Here is an example: my: 'value', other: "with ' single quote", num: 12.45, bool:true. This will be converted to a matching json object by simply applying a regex. While it may fail in very complex scenarios (in which case, use json), it's fine for most common use cases and makes handwriting config much more bearable.

There is a special syntax to pass callbacks like my: {__fn: 'app.callback'} which will result to {my: appCallbackFunctionReference}.

Simple configs can also point to a config provider using data-config="app.myConfigProvider()" which gets called on the global scope.

Passing a simple string like data-config="mystring" results to {default: "mystring"} object.

Simple params

When using list of string parameters, you can pass a selector or strings value that will be converted to proper vars.