-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(engine): abstraction for create/insert/remove/render to support CE #97
Conversation
if (vm.isDirty) { | ||
renderVM(vm); | ||
} | ||
renderVM(vm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderVM will take care of the check now.
const Ctor = getCtorByTagName(sel); | ||
const { forceTagName } = Ctor as ComponentConstructor; | ||
const tagName = isUndefined(forceTagName) ? sel : forceTagName; | ||
// Create element with correct tagName | ||
const element = document.createElement(tagName); | ||
if (hasOwnProperty.call(element, ViewModelReflection)) { | ||
return element; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the element is registered somehow, then the VM will be attached to it, and we don't have to carry on the hacks to detection insertion and removal, as well as the initial creation of the VM because it was already created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can this occur if we are creating brand new element right here?
} | ||
|
||
export function appendVM(vm: VM) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert.vm(vm); | ||
assert.isTrue(vm.idx === 0, `${vm} is already inserted.`); | ||
} | ||
if (vm.idx !== 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of an assertion, it is just a runtime check.
} | ||
rehydrate(vm); | ||
if (vm.isDirty) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of an assertion, it is just a runtime check.
} | ||
addInsertionIndex(vm); | ||
} | ||
|
||
export function removeVM(vm: VM) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert.vm(vm); | ||
assert.isTrue(vm.idx > 0, `${vm} is not inserted.`); | ||
} | ||
if (vm.idx === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of an assertion, it is just a runtime check.
@@ -128,6 +133,9 @@ export function createVM(tagName: string, elm: HTMLElement, cmpSlots?: Slotset) | |||
if (process.env.NODE_ENV !== 'production') { | |||
assert.invariant(elm instanceof HTMLElement, `VM creation requires a DOM element instead of ${elm}.`); | |||
} | |||
if (hasOwnProperty.call(elm, ViewModelReflection)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the VM was already attached, somewhere else, there is nothing to do here.
Benchmark comparisonBase commit:
|
…render to support CE
f8003ba
to
9d0379c
Compare
Benchmark comparisonBase commit:
|
Details
Instead of guarding in multiple places before carry-on any of these operations, we can just short-circuit on the spot. This will also help to support creation of registered elements.
Does this PR introduce a breaking change?