X Tutup
Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions modules/angular2/src/facade/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ var _clearValues: {(m: Map<any, any>)} = (function() {
};
}
})();
// Safari doesn't implement MapIterator.next(), which is used is Traceur's polyfill of Array.from
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a little unit test in collection_spec.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is already a unit test for that in collection_spec.ts:

describe('MapWrapper', () => {
      it('should return a list of keys values', () => {
        var m = new Map();
        m.set('a', 'b');
        expect(MapWrapper.keys(m)).toEqual(['a']);
        expect(MapWrapper.values(m)).toEqual(['b']);
      });
    });

// TODO(mlaval): remove the work around once we have a working polyfill of Array.from
var _arrayFromMap: {(m: Map<any, any>, getValues: boolean): List<any>} = (function() {
try {
if ((<any>(new Map()).values()).next) {
return function createArrayFromMap(m: Map<any, any>, getValues: boolean): List<any> {
return getValues ? (<any>Array).from(m.values()) : (<any>Array).from(m.keys());
};
}
} catch (e) {
}
return function createArrayFromMapWithForeach(m: Map<any, any>, getValues: boolean): List<any> {
var res = ListWrapper.createFixedSize(m.size), i = 0;
m.forEach((v, k) => {
ListWrapper.set(res, i, getValues ? v : k);
i++;
});
return res;
};
})();

export class MapWrapper {
static clone<K, V>(m: Map<K, V>): Map<K, V> { return createMapFromMap(m); }
Expand All @@ -74,8 +94,8 @@ export class MapWrapper {
static delete<K>(m: Map<K, any>, k: K) { m.delete(k); }
static clearValues(m: Map<any, any>) { _clearValues(m); }
static iterable<T>(m: T): T { return m; }
static keys<K>(m: Map<K, any>): List<K> { return (<any>Array).from(m.keys()); }
static values<V>(m: Map<any, V>): List<V> { return (<any>Array).from(m.values()); }
static keys<K>(m: Map<K, any>): List<K> { return _arrayFromMap(m, false); }
static values<V>(m: Map<any, V>): List<V> { return _arrayFromMap(m, true); }
}

/**
Expand Down
X Tutup