Exemplo n.º 1
0
export function mask_config (a?, b?, c?) {
	var args = arguments,
		length = args.length
	if (length === 0) {
		return __cfg;
	}
	if (length === 1) {
		let x = args[0]
		if (is_Object(x)) {
			obj_extend(__cfg, x);
			listeners_emit('config', x);
			return;
		}
		if (is_String(x)) {
			return obj_getProperty(__cfg, x);
		}
	}
	if (length === 2) {
		var prop = args[0];
		if (obj_hasProperty(__cfg, prop) === false) {
			log_warn('Unknown configuration property', prop);
		}
		let x = {};
		obj_setProperty(x    , prop, args[1]);
		obj_setProperty(__cfg, prop, args[1]);
		listeners_emit('config', x);
		return;
	}
}
Exemplo n.º 2
0
export function getSelfMutators(obj) {
    if (is_Object(obj) === false) {
        return null;
    }
    if (is_ArrayLike(obj)) {
        return MUTATORS_.Array;
    }
    if (is_Date(obj)) {
        return MUTATORS_.Date;
    }
    return null;
}
Exemplo n.º 3
0
export function u_setOption (options, key, val) {
    if (key === 'base' || key === 'nsBase') {
        var path = path_normalize(val);
        if (path[path.length - 1] !== '/') {
            path += '/';
        }
        // Do not resolve root, as it will be resolved by base later
        // @NextIteration: remove also path_resolveRoot, use instead resolveCurrent
        // if (path[0] === '/') {
        // 	path = path_combine(path_resolveRoot(), path);
        // }
        options[key] = path;
        return this;
    }
    var current = obj_getProperty(options, key);
    if (is_Object(current) && is_Object(val)) {
        obj_extend(current, val);
        return this;
    }
    obj_setProperty(options, key, val);
};
Exemplo n.º 4
0
export function m_cfg(mix, val){
    if (arguments.length === 1) {
        if (is_String(mix)) {
            return obj_getProperty(_opts, mix);
        }
        if (is_Object(mix)) {
            for (var key in mix) {
                u_setOption(_opts, key, mix[key]);
            }
        }
        return this;
    }
    u_setOption(_opts, mix, val);
    return this;
};
Exemplo n.º 5
0
export function _wrapper_CompoBuilder (decoNode, deco, builderFn) {
    let beforeRender, afterRender, decoCtx;

    if (is_Function(deco)) {
        beforeRender = deco;
    } else if (is_Object(deco)) {
        beforeRender = deco.beforeRender;
        afterRender = deco.afterRender;
        decoCtx = deco;
    }
    if (beforeRender || afterRender) {
        return create(decoCtx, beforeRender, afterRender, builderFn);
    }
    error_withNode('Invalid node decorator', decoNode);
};
Exemplo n.º 6
0
Arquivo: run.ts Projeto: atmajs/MaskJS
export function mask_run (){
		if (_state === 0) {
			_state = _state_All
		}
		var args = _Array_slice.call(arguments),
			model, ctx, el, Ctor;

		var imax = args.length,
			i = -1,
			mix;
		while ( ++i < imax ) {
			mix = args[i];
			if (mix instanceof Node) {
				el = mix;
				continue;
			}
			if (is_Function(mix)) {
				Ctor = mix;
				continue;
			}
			if (is_Object(mix)) {
				if (model == null) {
					model = mix;
					continue;
				}
				ctx = mix;
			}
		}

		if (el == null)
			el = document.body;
		if (Ctor == null)
			Ctor = Compo;
		if (model == null) {
			model = {};
		}

		var ctr = new Ctor(null, model, ctx, el);
		return _run(model, ctx, el, ctr);
	};
Exemplo n.º 7
0
Arquivo: ani.ts Projeto: atmajs/MaskJS
export function ani_updateAttr(compo, key, prop, val, meta) {
		var transition = compo.attr[key + '-transition'];
		if (transition == null && is_Object(meta)) {
			transition = meta.transition;
		}
		if (transition == null) {
			compo.attr[key] = val;
			if (prop != null) {
				compo[prop] = val;
			}
			_refresh(compo);
			return;
		}
		var tweens = compo.__tweens;
		if (tweens == null) {
			tweens = compo.__tweens = new TweenManager(compo);
		}

		var start = compo[prop];
		var end = val;
		tweens.start(key, prop, start, end, transition);
	};
Exemplo n.º 8
0
function fn_fromModel(model, prop) {
    if (is_Object(model) === false) {
        return null;
    }
    var Validate = model.Validate;
    if (Validate != null) {
        var fn = null;
        if (is_Function(fn = Validate)) {
            return fn;
        }
        if (is_Function(fn = Validate[prop])) {
            return fn;
        }
    }
    
    var i = prop.indexOf('.');
    if (i !== -1) {
        return fn_fromModel(
            model[prop.substring(0, i)], prop.substring(i+1)
        );
    }
    return null;
}
Exemplo n.º 9
0
	function compo_prototype(node, compoName, tagName, attr, nodes, owner, model, Base) {
		var arr = [];
		var selfFns = null;
		var Proto = obj_extend({
			tagName: tagName,
			compoName: compoName,
			template: arr,
			attr: attr,
			location: trav_location(owner),
			meta: {
				template: 'merge',
				arguments: node.arguments,
				statics: null
			},
			constructor: function DefineBase() {
				if (selfFns != null) {
					var i = selfFns.length;
					while(--i !== -1) {
						var key = selfFns[i];
						this[key] = this[key].bind(this);
					}
				}
			},			
			renderStart: function(model_, ctx, el){
				var model = model_;
				Component.prototype.renderStart.call(this, model, ctx, el);
				if (this.nodes === this.template && this.meta.template !== 'copy') {					
					this.nodes = mask_merge(this.nodes, [], this, null, mergeStats);
					if (mergeStats.placeholders.$isEmpty) {
						this.meta.template = 'copy';
					}
				}
			},
			getHandler: null
		}, Base);

		Methods.compileForDefine(node, Proto, model, owner);

		var imax = nodes == null ? 0 : nodes.length;
		for(var i = 0; i < imax; i++) {
			var decorators = null;
			var x = nodes[i];
			if (x == null) {
				continue;
			}
			if (x.type === Dom.DECORATOR) {
				var start = i;
				i = Decorator.goToNode(nodes, i, imax);
				decorators = _Array_slice.call(nodes, start, i);
				x = nodes[i];
			}
			
			var name = x.tagName;
			if ('function' === name) {
				if (name === 'constructor') {
					Proto.constructor = joinFns([Proto.constructor, x.fn]);
					continue;
				}
				var fn = x.fn;
				Proto[x.name] = fn;
				if (x.decorators != null) {
					var result = Decorator.wrapMethod(x.decorators, fn, Proto, x.name, model, null, owner);
					if (is_Function(result)) {
						Proto[x.name] = result;
					}
				}
				if (x.flagSelf) {
					selfFns = selfFns || [];
					selfFns.push(x.name);
				}
				if (x.flagStatic) {
					if (Proto.meta.statics == null) {
						Proto.meta.statics = {};
					}
					Proto.meta.statics[x.name] = fn;
				}
				continue;
			}
			if ('slot' === name || 'event' === name) {
				if ('event' === name && Proto.tagName != null) {
					// bind the event later via the component
					arr.push(x);
					continue;
				}
				var type = name + 's';
				var fns = Proto[type];
				if (fns == null) {
					fns = Proto[type] = {};
				}
				fns[x.name] = x.flagPrivate ? slot_privateWrap(x.fn) : x.fn;
				if (x.decorators != null) {
					var result = Decorator.wrapMethod(x.decorators, x.fn, fns, x.name, model, null, owner);
					if (is_Function(result)) {
						fns[x.name] = result;
					}
				}
				continue;
			}
			if ('pipe' === name) {
				custom_Tags.pipe.attach(x, Proto);
				continue;
			}
			if ('define' === name || 'let' === name) {
				var register = name === 'define'
					? Define.registerGlobal
					: Define.registerScoped;
				register(x, model, Proto);
				continue;
			}
			if ('var' === name) {
				var obj = x.getObject(model, null, owner),
					key, val;
				for(key in obj) {
					val = obj[key];
					if (key === 'meta' || key === 'model' || key === 'attr' || key === 'compos') {
						Proto[key] = obj_extend(Proto[key], val);
						continue;
					}
					if (key === 'scope') {
						if (is_Object(val)) {
							Proto.scope = obj_extend(Proto.scope, val);
							continue;
						}
					}
					var scope = Proto.scope;
					if (scope == null) {
						Proto.scope = scope = {};
					}
					scope[key] = val;
					Proto[key] = val;
				}
				continue;
			}

			if (decorators != null) {
				arr.push.apply(arr, decorators);
			}
			arr.push(x);
		}		
		return Proto;
	}
Exemplo n.º 10
0
import { is_Function, is_Object } from '@utils/is';
import { error_withNode } from '@core/util/reporters';
import {
    _wrapMany,
    _wrapper_NodeBuilder,
    _wrapper_CompoBuilder,
    _wrapper_Fn
} from './wrappers';
import { _getDecoType } from './utils';
import { _store } from './store';
import { Methods } from '../methods/exports';

export const Decorator = {
    getDecoType: _getDecoType,
    define(key, mix) {
        if (is_Object(mix)) {
            mix = class_create(mix);
            mix.isFactory = true;
        }
        if (is_Function(mix) && mix.isFactory) {
            // Wrap the function, as it could be a class, and decorator expression cann`t contain 'new' keyword.
            _store[key] = function() {
                return new (mix.bind.apply(
                    mix,
                    [null].concat(_Array_slice.call(arguments))
                ))();
            };
            _store[key].isFactory = true;
            return;
        }
        _store[key] = mix;