M
The members of the main object of the library.
On this page
M is a short name of MAIN. Most applications use the global functions instead of these members. For the concepts behind them, read Paths.
API
property
M.binders
An array of the active data bindings.
M.bindersSET('name', 'Peter');
setTimeout(function() {
console.log(M.binders.length); // 1
}, 300);
property
M.cl
The declared code lists by name.
M.clCL_INIT('roles', next => next([]));
console.log(Object.keys(M.cl)); // ["roles"]
method
M.compile([container])
Searches the page for new components and bindings.
M.compile([container])| Parameter | Type | Description |
|---|---|---|
container? |
Element|jQuery |
Limits the search to this element. |
Use COMPILE() in your code.
console.log(typeof(M.compile)); // function
property
M.components
An array of the created components.
M.componentsON('ready', function() {
console.log(M.components.length); // 2
});
property
M.days
The same array as DAYS.
M.daysconsole.log(M.days === DAYS); // true
method
M.default(path, [delay], [component], [reset])
Restores the default values of the components on a path.
M.default(path, [delay], [component], [reset])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
delay? |
Number |
A delay in milliseconds. |
component? |
Component |
Limits the change to one component. |
reset? |
Boolean |
With false, the state is kept. Default: true |
Use DEFAULT() in your code.
console.log(typeof(M.default)); // function
property
M.defaults
The same object as DEF.
M.defaultsconsole.log(M.defaults === DEF); // true
method
M.each(fn, [path])
Calls a function for each component.
M.each(fn, [path])| Parameter | Type | Description |
|---|---|---|
fn |
Function |
function(component, index, wildcard). |
path? |
String |
Limits the call to a path. |
Return true from the function to stop.
ON('ready', function() {
var paths = [];
M.each(com => paths.push(com.path), 'form.*');
console.log(paths.length); // 2
});
property
M.events
The registered event handlers by event name.
M.eventsON('hello', NOOP);
console.log(M.events.hello.length); // 1
method
M.extend(path, value, [type])
Merges fields into an object.
M.extend(path, value, [type])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
value |
Object |
The fields. |
type? |
Number |
The change type: 1 manual, 2 input, 3 default. |
Use EXT() for a delayed change.
SET('user', { a: 1 });
M.extend('user', { b: 2 });
console.log(GET('user')); // {"a":1,"b":2}
method
M.inc(path, value, [type])
Adds a number to a value.
M.inc(path, value, [type])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
value |
Number |
The number. |
type? |
Number |
The change type: 1 manual, 2 input, 3 default. |
Use INC() for a delayed change.
M.inc('count', 2);
console.log(GET('count')); // 2
property
M.loaded
true after the stored preferences are loaded.
M.loadedsetTimeout(function() {
console.log(M.loaded); // true
}, 500);
property
M.macros
The declared macros by name.
M.macrosMACRO('upper', NOOP);
console.log(typeof(M.macros.upper)); // function
property
M.months
The same array as MONTHS.
M.monthsconsole.log(M.months === MONTHS); // true
method
M.parse(type, value, [format])
Converts a value with the registered parsers.
M.parse(type, value, [format])| Parameter | Type | Description |
|---|---|---|
type |
String |
The type, for example number. |
value |
Object |
The value. |
format? |
String |
The format passed to the parsers. |
Returns Object The converted value.
console.log(M.parse('number', '5')); // 5
property
M.paths
The number of watchers and components for each path.
M.pathsWATCH('user.name', NOOP);
console.log(M.paths['user.name']); // 1
property
M.performance
Usage counters, collected when DEF.monitor is true.
M.performanceDEF.monitor = true;
GET('a');
console.log(M.performance.get.count > 0); // true
method
M.plugin([name])
Reads or changes the current plugin scope.
M.plugin([name])| Parameter | Type | Description |
|---|---|---|
name? |
String |
The new scope. |
Returns String The current scope.
M.plugin('users');
console.log(M.plugin()); // users
method
M.prototypes(fn)
Gives access to the prototypes of the library objects.
M.prototypes(fn)| Parameter | Type | Description |
|---|---|---|
fn |
Function |
function(proto). |
The object has the fields Component, Plugin and VBinder.
M.prototypes(function(proto) {
proto.Component.hello = () => 'Hello';
});
ON('ready', function() {
console.log(FIND('textbox').hello()); // Hello
});
method
M.push(path, value, [type])
Adds a value to an array.
M.push(path, value, [type])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
value |
Object |
The item. |
type? |
Number |
The change type: 1 manual, 2 input, 3 default. |
Use PUSH() for a delayed change.
M.push('list', 1);
console.log(GET('list')); // [1]
method
M.scope([name])
The same function as M.plugin().
M.scope([name])| Parameter | Type | Description |
|---|---|---|
name? |
String |
The new scope. |
Returns String The current scope.
console.log(M.scope === M.plugin); // true
property
M.scrollbars
An array of the custom scrollbars.
M.scrollbarsconsole.log(M.scrollbars.length); // 0
method
M.set(path, value, [type])
Writes a value to a path.
M.set(path, value, [type])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
value |
Object |
The value. |
type? |
Number |
The change type: 1 manual, 2 input, 3 default. |
Use SET() for a delayed change.
M.set('name', 'Peter');
console.log(GET('name')); // Peter
property
M.ua
The parsed user agent with the fields os, browser and device.
M.uaconsole.log(Object.keys(M.ua)); // ["os","browser","device"]
method
M.update(path, [reset], [type])
Refreshes everything bound to a path.
M.update(path, [reset], [type])| Parameter | Type | Description |
|---|---|---|
path |
String |
The path. |
reset? |
Boolean |
Resets the state of the components. |
type? |
Number |
The change type: 1 manual, 2 input, 3 default. |
Use UPD() for a delayed change.
SET('user', { name: 'Peter' });
WATCH('user.name', function(path, value) {
console.log(value); // Anna
});
GET('user').name = 'Anna';
M.update('user.name');
property
M.version
The version of the library.
M.versionconsole.log(M.version); // 19.194