Skip to content

Commit 8ee1156

Browse files
committed
feat(polyfills): ship with object.entries polyfill
1 parent 31d8b9f commit 8ee1156

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ You can find complete documentation on setup and usage in the official [Aurelia
1717

1818
* [RxJS v6](https://github.com/ReactiveX/rxjs)
1919
* aurelia-dependency-injection
20-
* aurelia-framework
20+
* aurelia-templating
2121
* aurelia-logging
2222
* aurelia-pal
2323

24+
## Polyfills
25+
26+
* Object.entries ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill))
27+
2428
## Platform Support
2529

2630
This library can be used in the **browser** and **node**.

src/aurelia-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./polyfills";
12
import { Store, StoreOptions } from "./store";
23
import { isStateHistory } from "./history";
34
import { Container } from "aurelia-dependency-injection";

src/decorator.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ export interface MultipleSelector<T, R = T | any> {
1919
const defaultSelector = <T>(store: Store<T>) => store.state;
2020

2121
export function connectTo<T, R = any>(settings?: ((store: Store<T>) => Observable<R>) | ConnectToSettings<T, R>) {
22-
if (!Object.entries) {
23-
throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill")
24-
}
25-
2622
let $store: Store<T>;
2723

2824
// const store = Container.instance.get(Store) as Store<T>;

src/polyfills.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* istanbul ignore next */
2+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill
3+
if (!Object.entries) {
4+
Object.entries = function(obj: any) {
5+
var ownProps = Object.keys(obj),
6+
i = ownProps.length,
7+
resArray = new Array(i); // preallocate the Array
8+
while (i--) {
9+
resArray[i] = [ownProps[i], obj[ownProps[i]]];
10+
}
11+
12+
return resArray;
13+
}
14+
}

test/unit/decorator.spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ describe("using decorators", () => {
2929
expect(typeof (component as any).bind).toBe("function");
3030
});
3131

32-
it("should throw an descriptive error if Object.entries is not available", () => {
33-
const originalEntries = (Object as any).entries;
34-
35-
(Object as any).entries = undefined;
36-
37-
expect(() => {
38-
connectTo();
39-
}).toThrowError(/Object.entries/);
40-
41-
(Object as any).entries = originalEntries;
42-
});
43-
4432
it("should be possible to decorate a class and assign the subscribed result to the state property", () => {
4533
const { initialState } = arrange();
4634

0 commit comments

Comments
 (0)