Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`$bind() [from-view] target=${$1} prop=${$2} newValue=${$3} expr=${$4} flags=${$5} scope=${$6}`, function () {
// - Arrange - Part 1
const { sut, lifecycle, container, observerLocator } = createFixture(expr, target, prop, BindingMode.fromView);
const targetObserver = observerLocator.getObserver(LF.none, target, prop) as IBindingTargetObserver;
// massSpy(targetObserver, 'subscribe');
// ensureNotCalled(expr, 'evaluate', 'connect', 'assign');
// ensureNotCalled(targetObserver, 'setValue', 'getValue', 'removeSubscriber', 'callSubscribers');
// ensureNotCalled(sut, 'handleChange');
const initialVal = target[prop];
// - Act - Part 1
sut.$bind(flags, scope);
// - Assert - Part 1
// assert.strictEqual(lifecycle.flushCount, 0, `lifecycle.flushCount`);
assert.instanceOf(sut.targetObserver, SetterObserver, `sut.targetObserver`);
handleChange(newValue, _previousValue, flags) {
if (!(this.$state & 4 /* isBound */)) {
return;
}
flags |= this.persistentFlags;
if (this.mode === BindingMode.fromView) {
flags &= ~16 /* updateTargetInstance */;
flags |= 32 /* updateSourceExpression */;
}
if (flags & 16 /* updateTargetInstance */) {
const previousValue = this.targetObserver.getValue();
// if the only observable is an AccessScope then we can assume the passed-in newValue is the correct and latest value
if (this.sourceExpression.$kind !== 10082 /* AccessScope */ || this.observerSlots > 1) {
newValue = this.sourceExpression.evaluate(flags, this.$scope, this.locator, this.part);
}
if (newValue !== previousValue) {
this.interceptor.updateTarget(newValue, flags);
}
if ((this.mode & oneTime) === 0) {
this.version++;
this.sourceExpression.connect(flags, this.$scope, this.interceptor, this.part);
this.interceptor.unobserve(false);
}
public compile(binding: PlainAttributeSymbol | BindingSymbol): AttributeInstruction {
return new TwoWayBindingInstruction(binding.expression as IsBindingBehavior, getTarget(binding, false));
}
}
BindingCommandResource.define('two-way', TwoWayBindingCommand);
// Not bothering to throw on non-existing modes, should never happen anyway.
// Keeping all array elements of the same type for better optimizeability.
const modeToProperty = ['', '$1', '$2', '', '$4', '', '$6'];
const commandToMode = {
'bind': BindingMode.toView,
'one-time': BindingMode.oneTime,
'to-view': BindingMode.toView,
'from-view': BindingMode.fromView,
'two-way': BindingMode.twoWay,
};
export interface DefaultBindingCommand extends IBindingCommand {}
export class DefaultBindingCommand implements IBindingCommand {
public static readonly register: IRegistry['register'];
public readonly bindingType: BindingType.BindCommand;
public readonly $1: typeof OneTimeBindingCommand.prototype.compile;
public readonly $2: typeof ToViewBindingCommand.prototype.compile;
public readonly $4: typeof FromViewBindingCommand.prototype.compile;
public readonly $6: typeof TwoWayBindingCommand.prototype.compile;
constructor() {
this.bindingType = BindingType.BindCommand;
this.$1 = OneTimeBindingCommand.prototype.compile;
this.$2 = ToViewBindingCommand.prototype.compile;
if ('template' in subject) { // Raw Template Definition
const definition = CustomElementDefinition.getOrCreate(subject);
return getRenderContext(definition, this.$controller.context, void 0).getViewFactory().create(flags);
}
// Constructable (Custom Element Constructor)
return createElement(this.dom, subject, this.properties, this.$controller.projector === void 0
? PLATFORM.emptyArray
: this.$controller.projector.children).createView(this.$controller.context);
}
};
__decorate([
bindable,
__metadata("design:type", Object)
], Compose.prototype, "subject", void 0);
__decorate([
bindable({ mode: BindingMode.fromView }),
__metadata("design:type", Boolean)
], Compose.prototype, "composing", void 0);
Compose = __decorate([
customElement({ name: 'au-compose', template: null, containerless: true }),
__param(0, IDOM),
__param(1, ITargetedInstruction),
__metadata("design:paramtypes", [Object, Object])
], Compose);
export { Compose };
function isController(subject) {
return 'lockScope' in subject;
}
//# sourceMappingURL=compose.js.map
};
const outputMarkup = ctx.createElementFromMarkup(`<div>${(childOutput && childOutput.template.outerHTML) || ''}</div>`);
outputMarkup.classList.add('au');
const output = {
template: finalize ? ctx.createElementFromMarkup(`<template><div>${outputMarkup.outerHTML}</div></template>`) : outputMarkup,
instructions: [[instruction, ...siblingInstructions], ...nestedElInstructions],
build: buildNotRequired,
scopeParts: [],
};
return [input, output];
}
const commandToMode = {
'one-time': BindingMode.oneTime,
'to-view': BindingMode.toView,
'from-view': BindingMode.fromView,
'two-way': BindingMode.twoWay
};
const validCommands = ['bind', 'one-time', 'to-view', 'from-view', 'two-way', 'trigger', 'delegate', 'capture', 'call'];
function createAttributeInstruction(bindableDescription: IBindableDescription | null, attributeName: string, attributeValue: string, isMulti: boolean) {
const parts = attributeName.split('.');
const attr = parts[0];
const cmd = parts.pop();
const defaultMode = !!bindableDescription ? (bindableDescription.mode === BindingMode.default ? BindingMode.toView : bindableDescription.mode) : BindingMode.toView;
const mode = commandToMode[cmd] || defaultMode;
const oneTime = mode === BindingMode.oneTime;
if (!!bindableDescription) {
if (!!cmd && validCommands.includes(cmd)) {
const type = TT.propertyBinding;
getBindingMode() { return BindingMode.fromView; },
getExpectedBindingMode(def: IAttributeDefinition) {
<template>
</template>
`;
assert.deepEqual(stripMetaData(html), {
html: expected,
shadowMode: null,
deps: [],
containerless: false,
bindables: {
firstName: { mode: BindingMode.toView },
lastName: { mode: BindingMode.twoWay, attribute: 'surname' },
foo: { mode: BindingMode.oneTime },
bar: { mode: BindingMode.toView },
lo: { mode: BindingMode.fromView}
}
});
});
public compile(binding: PlainAttributeSymbol | BindingSymbol): AttributeInstruction {
let mode: BindingMode = BindingMode.default;
if (binding instanceof BindingSymbol) {
mode = binding.bindable.mode;
} else {
const command = binding.syntax.command;
switch (command) {
case 'bind':
case 'to-view':
mode = BindingMode.toView;
break;
case 'one-time':
mode = BindingMode.oneTime;
break;
case 'from-view':
mode = BindingMode.fromView;
break;
case 'two-way':
mode = BindingMode.twoWay;
break;
}
}
switch (mode) {
case BindingMode.default:
case BindingMode.toView:
return ToViewBindingCommand.prototype.compile(binding);
case BindingMode.oneTime:
return OneTimeBindingCommand.prototype.compile(binding);
case BindingMode.fromView:
return FromViewBindingCommand.prototype.compile(binding);
case BindingMode.twoWay:
function toBindingMode(mode) {
if (mode) {
const normalizedMode = kebabCase(mode);
if (normalizedMode === 'one-time')
return BindingMode.oneTime;
if (normalizedMode === 'one-way' || normalizedMode === 'to-view')
return BindingMode.toView;
if (normalizedMode === 'from-view')
return BindingMode.fromView;
if (normalizedMode === 'two-way')
return BindingMode.twoWay;
}
}
//# sourceMappingURL=strip-meta-data.js.map
case 'from-view':
mode = BindingMode.fromView;
break;
case 'two-way':
mode = BindingMode.twoWay;
break;
}
}
switch (mode) {
case BindingMode.default:
case BindingMode.toView:
return ToViewBindingCommand.prototype.compile(binding);
case BindingMode.oneTime:
return OneTimeBindingCommand.prototype.compile(binding);
case BindingMode.fromView:
return FromViewBindingCommand.prototype.compile(binding);
case BindingMode.twoWay:
return TwoWayBindingCommand.prototype.compile(binding);
}
}
}