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): issue #153 adds a mechanism for LDS to create readonly obj #154

Merged
merged 2 commits into from
Mar 15, 2018

Conversation

caridy
Copy link
Contributor

@caridy caridy commented Mar 14, 2018

This PR introduces a preliminary way for LDS and other libs to create qualifying objects that can be consumed by LWC (without a degradation), and at the same time, facilitate the creation of readonly and track objects in those libraries without the double proxification.

Does this PR introduce a breaking change?

  • No

Features

  • introduce readonly method that can be imported from "engine".
  • open up the ability to call track as a method, instead of just being a decorator.
const something = { x: 1, y: { z: 2 }};
const foo = readonly(something);
const bar = track(something);

Invariants

  • a readonly object can't be tracked anymore because track means that you will attempt to mutate it at some point. it now throws.

@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: 7c91533 | Target commit: a906e16

benchmark base(7c91533) target(a906e16) trend
table-append-1k.benchmark:benchmark-table/append/1k 272.77 (± 2.62 ms) 291.77 (± 11.74 ms) 👎
table-clear-1k.benchmark:benchmark-table/clear/1k 13.53 (± 0.54 ms) 16.05 (± 0.78 ms) 👎
table-create-10k.benchmark:benchmark-table/create/10k 1516.63 (± 10.28 ms) 1543.56 (± 25.70 ms) 👎
table-create-1k.benchmark:benchmark-table/create/1k 162.79 (± 2.83 ms) 164.78 (± 3.71 ms) 👌
table-update-10th-1k.benchmark:benchmark-table/update-10th/1k 138.72 (± 3.56 ms) 149.71 (± 3.41 ms) 👎
tablecmp-append-1k.benchmark:benchmark-table-component/append/1k 356.64 (± 4.73 ms) 373.48 (± 8.56 ms) 👎
tablecmp-clear-1k.benchmark:benchmark-table/clear/1k 34.90 (± 1.15 ms) 37.69 (± 2.61 ms) 👎
tablecmp-create-10k.benchmark:benchmark-table-component/create/10k 2668.68 (± 20.22 ms) 2806.21 (± 28.22 ms) 👎
tablecmp-create-1k.benchmark:benchmark-table-component/create/1k 293.61 (± 4.44 ms) 339.42 (± 10.69 ms) 👎
tablecmp-update-10th-1k.benchmark:benchmark-table-component/update-10th/1k 150.71 (± 3.35 ms) 156.02 (± 6.22 ms) 👎

@salesforce-best-lwc-internal
Copy link

Benchmark comparison

Base commit: dd03fe4 | Target commit: 50b5fa8

benchmark base(dd03fe4) target(50b5fa8) trend
table-append-1k.benchmark:benchmark-table/append/1k 263.67 (± 2.56 ms) 282.87 (± 3.91 ms) 👎
table-clear-1k.benchmark:benchmark-table/clear/1k 12.68 (± 0.34 ms) 14.73 (± 0.42 ms) 👎
table-create-10k.benchmark:benchmark-table/create/10k 1484.24 (± 8.05 ms) 1531.36 (± 18.41 ms) 👎
table-create-1k.benchmark:benchmark-table/create/1k 158.00 (± 1.23 ms) 169.63 (± 3.75 ms) 👎
table-update-10th-1k.benchmark:benchmark-table/update-10th/1k 135.63 (± 3.68 ms) 147.16 (± 3.10 ms) 👎
tablecmp-append-1k.benchmark:benchmark-table-component/append/1k 362.67 (± 7.57 ms) 364.20 (± 10.73 ms) 👌
tablecmp-clear-1k.benchmark:benchmark-table/clear/1k 34.23 (± 0.90 ms) 36.30 (± 2.30 ms) 👎
tablecmp-create-10k.benchmark:benchmark-table-component/create/10k 2624.49 (± 23.60 ms) 2738.68 (± 29.08 ms) 👎
tablecmp-create-1k.benchmark:benchmark-table-component/create/1k 290.65 (± 2.70 ms) 311.02 (± 9.78 ms) 👎
tablecmp-update-10th-1k.benchmark:benchmark-table-component/update-10th/1k 142.08 (± 2.03 ms) 152.60 (± 2.10 ms) 👎

@@ -52,7 +52,7 @@ export const unwrap = getKey ?
: (replicaOrAny: any): any => (replicaOrAny && replicaOrAny[TargetSlot]) || replicaOrAny;

export function isObservable(value: any): boolean {
if (!value) {
if (value == null) {
Copy link
Contributor

@davidturissini davidturissini Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't sufficient. We need to check for undefined because getPrototypeOf(undefined) throws.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is ==, which means it checks for null and undefined without coercion.

@caridy caridy merged commit 3de8834 into master Mar 15, 2018
@caridy caridy deleted the caridy/issue-153/exposing-readonly-factory branch March 15, 2018 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants