Skip to content

Commit

Permalink
rix(repeat): fix keyed issues & contextual property optimization (#2050)
Browse files Browse the repository at this point in the history
* wip

* fix(repeat): set contextual properties for sort ops

* refactor(repeat): get key from oldViews

* refactor(repeat): overhaul scope / key caching

* refactor(repeat): bust key cache

* refactor(repeat): fix newKey thing

* wip: pre-nuke backup

* refactor(repeat): inefficient but working thing

* perf(repeat): pass 1

* perf(repeat): pass 2

* refactor(repeat): fix update issue

* refactor(repeat): more bugfixing / cleanup

* refactor(repeat): cleanup unnecessary stuff

* test(repeat): mutations?

* chore(repeat): internal props
  • Loading branch information
fkleuver authored Sep 20, 2024
1 parent c5dfca3 commit 9834c40
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 238 deletions.
34 changes: 22 additions & 12 deletions packages/__tests__/src/3-runtime-html/repeat.duplicates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,101 @@ import { createFixture } from "@aurelia/testing";
describe("3-runtime-html/repeat.duplicates.spec.ts", function () {
describe('yield correct $index', function () {
it('duplicate primitive string', function () {
const { assertText, component } = createFixture(
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = ['a', 'b', 'a']; }
);
assertText('0-a 1-b 2-a ');

component.items.push('a');
flush();

assertText('0-a 1-b 2-a 3-a ');
});

it.skip('duplicate primitive string + push + sort', function () {
const { assertText, component } = createFixture(
it('duplicate primitive string + push + sort', function () {
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = ['a', 'b', 'a']; }
);
assertText('0-a 1-b 2-a ');

component.items.sort();
flush();

assertText('0-a 1-a 2-b ');
});

it('duplicate primitive number', function () {
const { assertText, component } = createFixture(
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = [0, 1, 0]; }
);
assertText('0-0 1-1 2-0 ');

component.items.push(0);
flush();

assertText('0-0 1-1 2-0 3-0 ');
});

it.skip('duplicate primitive number + sort', function () {
const { assertText, component } = createFixture(
it('duplicate primitive number + sort', function () {
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = [0, 1, 0]; }
);
assertText('0-0 1-1 2-0 ');

component.items.sort();
flush();

assertText('0-0 1-0 2-0 3-1 ');
assertText('0-0 1-0 2-1 ');
});

it('duplicate object', function () {
const obj0 = { toString() { return '0'; } };
const obj1 = { toString() { return '1'; } };

const { assertText, component } = createFixture(
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = [obj0, obj1, obj0]; }
);
assertText('0-0 1-1 2-0 ');

component.items.push(obj0);
flush();

assertText('0-0 1-1 2-0 3-0 ');
});

it.skip('duplicate object + sort', function () {
it('duplicate object + sort', function () {
const obj0 = { toString() { return '0'; } };
const obj1 = { toString() { return '1'; } };

const { assertText, component } = createFixture(
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = [obj0, obj1, obj0]; }
);
assertText('0-0 1-1 2-0 ');

component.items.sort();
flush();

assertText('0-0 1-0 2-1 ');
});

// TODO: fix contextual props $index when sorting
it.skip('primitive string + sort (move to contextual props tests)', function () {
const { assertText, component } = createFixture(
// it('primitive string + sort (move to contextual props tests)', function () {
it('primitive string + sort (move to contextual props tests)', function () {
const { assertText, component, flush } = createFixture(
`<div repeat.for="i of items">\${$index}-\${i} </div>`,
class { items = ['c', 'b', 'a']; }
);
assertText('0-c 1-b 2-a ');

component.items.sort();
flush();

assertText('0-a 1-b 2-c ');
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-html/src/binding/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export class Scope {
return new Scope(null, bc as IBindingContext, oc ?? new OverrideContext(), isBoundary ?? false);
}

public static fromParent(ps: Scope | null, bc: object): Scope {
public static fromParent(ps: Scope | null, bc: object, oc: IOverrideContext = new OverrideContext()): Scope {
if (ps == null) {
throw createMappedError(ErrorNames.null_scope);
}
return new Scope(ps, bc as IBindingContext, new OverrideContext(), false);
return new Scope(ps, bc as IBindingContext, oc, false);
}
}

Expand Down
Loading

0 comments on commit 9834c40

Please sign in to comment.