Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should set element to simple empty div as the default render implementation', function() {
var component = new Component();
renderer = new ComponentRenderer(component);
component.emit('render');
assert.ok(core.isElement(component.element));
assert.strictEqual('DIV', component.element.tagName);
});
it('should intercept attribute calls with specified function', function() {
var original = IncrementalDomAop.getOriginalFns().attributes;
var fn = sinon.stub();
IncrementalDomAop.startInterception({
attributes: fn
});
var element = document.createElement('div');
IncrementalDOM.attributes[IncrementalDOM.symbols.default](element, 'name', 'value');
assert.strictEqual(1, fn.callCount);
assert.strictEqual(original, fn.args[0][0]);
assert.ok(core.isElement(fn.args[0][1]));
assert.strictEqual('name', fn.args[0][2]);
assert.strictEqual('value', fn.args[0][3]);
});
handle() {
if (!isElement(this.baseElement)) {
throw new Error('Senna data attribute handler base element ' +
'not set or invalid, try setting a valid element that ' +
'contains a `data-senna` attribute.');
}
if (!this.baseElement.hasAttribute(dataAttributes.senna)) {
console.log('Senna was not initialized from data attributes. ' +
'In order to enable its usage from data attributes try setting ' +
'in the base element, e.g. ``.');
return;
}
if (this.app) {
throw new Error('Senna app was already initialized.');
}
set element(val) {
if (!isElement(val) && !isString(val) && isDefAndNotNull(val)) {
return;
}
if (val) {
val = toElement(val) || this.elementValue_;
}
if (this.elementValue_ !== val) {
const prev = this.elementValue_;
this.elementValue_ = val;
this.handleComponentElementChanged_(prev, val);
}
}
set element(val) {
if (!isElement(val) && !isString(val) && isDefAndNotNull(val)) {
return;
}
if (val) {
val = toElement(val) || this.elementValue_;
}
if (this.elementValue_ !== val) {
const prev = this.elementValue_;
this.elementValue_ = val;
this.handleComponentElementChanged_(prev, val);
}
}
setUpPortal_(portalElement) {
if (
!portalElement ||
(!isElement(portalElement) &&
!isString(portalElement) &&
!isBoolean(portalElement))
) {
return;
} else if (isBoolean(portalElement) && portalElement) {
portalElement = 'body';
}
if (isServerSide()) {
this.portalElement = true;
return;
}
portalElement = this.getPortalElement_(portalElement);
if (portalElement) {
export function toElement(selectorOrElement) {
if (
isElement(selectorOrElement) ||
isDocument(selectorOrElement) ||
isDocumentFragment(selectorOrElement)
) {
return selectorOrElement;
} else if (isString(selectorOrElement)) {
return document.querySelector(selectorOrElement);
} else {
return null;
}
}
static render(Ctor, opt_configOrElement, opt_element) {
let config = opt_configOrElement;
let element = opt_element;
if (isElement(opt_configOrElement)) {
config = null;
element = opt_configOrElement;
}
const instance = new Ctor(config, false);
instance.renderComponent(element);
return instance;
}
static render(Ctor, configOrElement, element) {
let config = configOrElement;
if (isElement(configOrElement)) {
config = null;
element = configOrElement;
}
const instance = new Ctor(config, false);
instance.renderComponent(element);
return instance;
}