Skip to content

Commit

Permalink
Make Phantom happy
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Jun 19, 2017
1 parent b1ef501 commit 9c690dd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
13 changes: 11 additions & 2 deletions packages/@glimmer/runtime/lib/vm/rehydrate-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class RehydrateBuilder extends NewElementBuilder implements ElementBuilde
let unmatched = this.unmatchedAttributes;

if (unmatched) {
let attr = unmatched.find(a => a.name === name);
let attr = findByName(unmatched, name);
if (attr) {
attr.value = value;
unmatched.splice(unmatched.indexOf(attr), 1);
Expand All @@ -219,7 +219,7 @@ export class RehydrateBuilder extends NewElementBuilder implements ElementBuilde
let unmatched = this.unmatchedAttributes;

if (unmatched) {
let attr = unmatched.find(a => a.name === name);
let attr = findByName(unmatched, name);
if (attr) {
attr.value = value;
unmatched.splice(unmatched.indexOf(attr), 1);
Expand Down Expand Up @@ -342,6 +342,15 @@ function remove(node: Simple.Node): Option<Simple.Node> {
return next;
}

function findByName(array: Simple.Attribute[], name: string): Simple.Attribute | undefined {
for (let i = 0; i < array.length; i++) {
let attr = array[i];
if (attr.name === name) return attr;
}

return undefined;
}

function unimplemented() {
return new Error('Not implemented');
}
27 changes: 16 additions & 11 deletions packages/@glimmer/runtime/test/new-initial-render-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,13 @@ abstract class RenderTest {
return callback();
}

protected assertStableNodes({ except: _except }: { except: Set<Node> | Node | Node[] } = { except: new Set() }) {
let except: Set<Node>;
protected assertStableNodes({ except: _except }: { except: Array<Node> | Node | Node[] } = { except: [] }) {
let except: Array<Node>;

if (Array.isArray(_except)) {
except = new Set(_except);
} else if (_except instanceof Set) {
except = _except;
except = uniq(_except);
} else {
except = new Set([_except]);
except = [_except];
}

let { oldSnapshot, newSnapshot } = normalize(this.snapshot, this.takeSnapshot(), except);
Expand Down Expand Up @@ -357,13 +355,13 @@ module("Initial Render Tests", class extends RenderTest {
}
});

type Content = string | typeof OPEN | typeof CLOSE | typeof SEP | typeof EMPTY;

const OPEN: { marker: 'open-block' } = { marker: 'open-block' };
const CLOSE: { marker: 'close-block' } = { marker: 'close-block' };
const SEP: { marker: 'sep' } = { marker: 'sep' };
const EMPTY: { marker: 'empty' } = { marker: 'empty' };

type Content = string | typeof OPEN | typeof CLOSE | typeof SEP | typeof EMPTY;

function content(list: Content[]): string {
let out: string[] = [];
let depth = 0;
Expand Down Expand Up @@ -526,7 +524,7 @@ function renderTemplate(env: TestEnvironment, template: Template<Opaque>, option
return result;
}

function normalize(oldSnapshot: NodesSnapshot, newSnapshot: NodesSnapshot, except: Set<Node>) {
function normalize(oldSnapshot: NodesSnapshot, newSnapshot: NodesSnapshot, except: Array<Node>) {
let oldIterator = new SnapshotIterator(oldSnapshot);
let newIterator = new SnapshotIterator(newSnapshot);

Expand All @@ -539,7 +537,7 @@ function normalize(oldSnapshot: NodesSnapshot, newSnapshot: NodesSnapshot, excep

if (nextOld === null && newIterator.peek() === null) break;

if ((nextOld instanceof Node && except.has(nextOld)) || (nextNew instanceof Node && except.has(nextNew))) {
if ((nextOld instanceof Node && except.indexOf(nextOld) > -1) || (nextNew instanceof Node && except.indexOf(nextNew) > -1)) {
oldIterator.skip();
newIterator.skip();
} else {
Expand Down Expand Up @@ -590,6 +588,13 @@ class SnapshotIterator {
}
}

function uniq(arr: any[]) {
return arr.reduce((accum, val) => {
if (accum.indexOf(val) === -1) accum.push(val);
return accum;
}, []);
}

function isServerMarker(node: Node) {
return node.nodeType === Node.COMMENT_NODE && node.nodeValue!.charAt(0) === '%';
}
}
2 changes: 1 addition & 1 deletion packages/@glimmer/util/lib/array-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ if (HAS_TYPED_ARRAYS) {

export default A;

export const EMPTY_ARRAY: any[] = (HAS_NATIVE_WEAKMAP ? Object.freeze([]) : []) as any;
export const EMPTY_ARRAY: any[] = (HAS_NATIVE_WEAKMAP ? Object.freeze([]) : []) as any;

0 comments on commit 9c690dd

Please sign in to comment.