Skip to content
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

Merged
merged 1 commit into from
Feb 13, 2018

Conversation

caridy
Copy link
Contributor

@caridy caridy commented Feb 13, 2018

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?

  • Yes
  • No

if (vm.isDirty) {
renderVM(vm);
}
renderVM(vm);
Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

Copy link
Collaborator

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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)) {
Copy link
Contributor Author

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.

@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: 93c73fe | Target commit: f8003ba

benchmark base(93c73fe) target(f8003ba) trend

@caridy caridy force-pushed the caridy/custom-element-vs-raptor-element branch from f8003ba to 9d0379c Compare February 13, 2018 18:09
@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: 93c73fe | Target commit: 9d0379c

benchmark base(93c73fe) target(9d0379c) trend
table-append-1k.benchmark:benchmark-table/append/1k 248.98 (± 3.64 ms) 253.88 (± 5.98 ms) 👎
table-clear-1k.benchmark:benchmark-table/clear/1k 12.80 (± 0.45 ms) 13.79 (± 0.63 ms) 👎
table-create-10k.benchmark:benchmark-table/create/10k 1386.06 (± 27.92 ms) 1439.77 (± 33.71 ms) 👎
table-create-1k.benchmark:benchmark-table/create/1k 149.38 (± 1.35 ms) 151.64 (± 2.50 ms) 👎
table-update-10th-1k.benchmark:benchmark-table/update-10th/1k 142.37 (± 3.00 ms) 143.82 (± 4.51 ms) 👌
tablecmp-append-1k.benchmark:benchmark-table-component/append/1k 332.50 (± 7.70 ms) 319.60 (± 7.02 ms) 👍
tablecmp-clear-1k.benchmark:benchmark-table/clear/1k 32.83 (± 1.45 ms) 32.31 (± 1.34 ms) 👌
tablecmp-create-10k.benchmark:benchmark-table-component/create/10k 2033.78 (± 25.73 ms) 2097.85 (± 37.14 ms) 👎
tablecmp-create-1k.benchmark:benchmark-table-component/create/1k 229.59 (± 2.65 ms) 235.03 (± 5.68 ms) 👎
tablecmp-update-10th-1k.benchmark:benchmark-table-component/update-10th/1k 130.75 (± 4.21 ms) 132.95 (± 3.88 ms) 👎

@caridy caridy changed the title feat(engine): refactoring abstraction for create/insert/remove/render to support CE feat(engine): abstraction for create/insert/remove/render to support CE Feb 13, 2018
@caridy caridy merged commit 4b3b3d9 into master Feb 13, 2018
@caridy caridy deleted the caridy/custom-element-vs-raptor-element branch February 13, 2018 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants