How to use the metal.isString function in metal

To help you get started, we’ve selected a few metal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metal / metal.js / packages / metal-dom / src / domNamed.js View on Github external
if (defaultListener) {
		// Wrap callback so we don't set property directly on it.
		callback = callback.bind();
		callback.defaultListener_ = true;
	}

	attachDelegateEvent_(element, eventName);
	if (isString(selectorOrTarget)) {
		addSelectorListener_(element, eventName, selectorOrTarget, callback);
	} else {
		addElementListener_(selectorOrTarget, eventName, callback);
	}

	return new DomDelegatedEventHandle(
		isString(selectorOrTarget) ? element : selectorOrTarget,
		eventName,
		callback,
		isString(selectorOrTarget) ? selectorOrTarget : null
	);
}
github metal / metal.js / packages / metal-dom / src / domNamed.js View on Github external
defaultListener
) {
	const customConfig = customEvents[eventName];
	if (customConfig && customConfig.delegate) {
		eventName = customConfig.originalEvent;
		callback = customConfig.handler.bind(customConfig, callback);
	}

	if (defaultListener) {
		// Wrap callback so we don't set property directly on it.
		callback = callback.bind();
		callback.defaultListener_ = true;
	}

	attachDelegateEvent_(element, eventName);
	if (isString(selectorOrTarget)) {
		addSelectorListener_(element, eventName, selectorOrTarget, callback);
	} else {
		addElementListener_(selectorOrTarget, eventName, callback);
	}

	return new DomDelegatedEventHandle(
		isString(selectorOrTarget) ? element : selectorOrTarget,
		eventName,
		callback,
		isString(selectorOrTarget) ? selectorOrTarget : null
	);
}
github metal / metal.js / packages / metal-events / src / EventEmitter.js View on Github external
toEventsArray_(events) {
		if (isString(events)) {
			singleArray_[0] = events;
			events = singleArray_;
		}
		return events;
	}
github metal / metal.js / packages / metal-dom / src / domNamed.js View on Github external
export function removeClasses(elements, classes) {
	if (!isObject(elements) || !isString(classes)) {
		return;
	}

	if (!elements.length) {
		elements = [elements];
	}

	for (let i = 0; i < elements.length; i++) {
		if ('classList' in elements[i]) {
			removeClassesWithNative_(elements[i], classes);
		} else {
			removeClassesWithoutNative_(elements[i], classes);
		}
	}
}
github metal / metal.js / packages / metal-incremental-dom / src / render / render.js View on Github external
function getSubComponent_(tagOrCtor, config, owner) {
	let Ctor = tagOrCtor;
	if (isString(Ctor)) {
		Ctor = ComponentRegistry.getConstructor(tagOrCtor);
	}

	const ref = getRef_(owner, config);
	let comp;
	if (isDef(ref)) {
		comp = match_(owner.components[ref], Ctor, config, owner);
		owner.components[ref] = comp;
		owner.refs[ref] = comp;
	} else {
		const data = getCurrentData();
		let key = config.key;
		if (!isDef(key)) {
			const type = getUid(Ctor, true);
			data.currCount = data.currCount || {};
			data.currCount[type] = data.currCount[type] || 0;
github metal / metal.js / packages / metal-incremental-dom / src / render / render.js View on Github external
function inheritElementClasses_(parent, config) {
	const parentData = getData(parent);
	const parentConfig = parentData.config;

	if (
		!parentData.rootElementReached &&
		parentConfig &&
		isString(parentConfig.elementClasses)
	) {
		let currentClasses = '';
		if (isString(config.elementClasses)) {
			currentClasses = `${config.elementClasses} `;
		}

		config.elementClasses = currentClasses + parentConfig.elementClasses;
	}
}
github LiferayCloud / magnet / src / plugin / metal.js View on Github external
function renderLayoutToString(fnOrString) {
  if (isString(fnOrString)) {
    return fnOrString;
  }
  try {
    const element = {};
    IncrementalDOM.patch(element, () => fnOrString);
    return element.innerHTML;
  } catch (error) {
    throw new Error(
      `Metal.js layout type defined in this route cannot be rendered ` +
        `from the server, only String or JSX layouts are supported.`
    );
  }
}
github metal / metal.js / packages / metal-dom / src / domNamed.js View on Github external
export function on(element, eventName, callback, capture) {
	if (isString(element)) {
		return delegate(document, eventName, element, callback);
	}
	const customConfig = customEvents[eventName];
	if (customConfig && customConfig.event) {
		eventName = customConfig.originalEvent;
		callback = customConfig.handler.bind(customConfig, callback);
	}
	element.addEventListener(eventName, callback, capture);
	return new DomEventHandle(element, eventName, callback, capture);
}