Skip to content

Commit

Permalink
feat(polyfills): ship with object.entries polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
zewa666 committed Jun 9, 2019
1 parent 31d8b9f commit 8ee1156
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -17,10 +17,14 @@ You can find complete documentation on setup and usage in the official [Aurelia


* [RxJS v6](https://github.com/ReactiveX/rxjs) * [RxJS v6](https://github.com/ReactiveX/rxjs)
* aurelia-dependency-injection * aurelia-dependency-injection
* aurelia-framework * aurelia-templating
* aurelia-logging * aurelia-logging
* aurelia-pal * aurelia-pal


## Polyfills

* Object.entries ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill))

## Platform Support ## Platform Support


This library can be used in the **browser** and **node**. This library can be used in the **browser** and **node**.
Expand Down
1 change: 1 addition & 0 deletions src/aurelia-store.ts
@@ -1,3 +1,4 @@
import "./polyfills";
import { Store, StoreOptions } from "./store"; import { Store, StoreOptions } from "./store";
import { isStateHistory } from "./history"; import { isStateHistory } from "./history";
import { Container } from "aurelia-dependency-injection"; import { Container } from "aurelia-dependency-injection";
Expand Down
4 changes: 0 additions & 4 deletions src/decorator.ts
Expand Up @@ -19,10 +19,6 @@ export interface MultipleSelector<T, R = T | any> {
const defaultSelector = <T>(store: Store<T>) => store.state; const defaultSelector = <T>(store: Store<T>) => store.state;


export function connectTo<T, R = any>(settings?: ((store: Store<T>) => Observable<R>) | ConnectToSettings<T, R>) { export function connectTo<T, R = any>(settings?: ((store: Store<T>) => Observable<R>) | ConnectToSettings<T, R>) {
if (!Object.entries) {
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")
}

let $store: Store<T>; let $store: Store<T>;


// const store = Container.instance.get(Store) as Store<T>; // const store = Container.instance.get(Store) as Store<T>;
Expand Down
14 changes: 14 additions & 0 deletions src/polyfills.ts
@@ -0,0 +1,14 @@
/* istanbul ignore next */
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill
if (!Object.entries) {
Object.entries = function(obj: any) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--) {
resArray[i] = [ownProps[i], obj[ownProps[i]]];
}

return resArray;
}
}
12 changes: 0 additions & 12 deletions test/unit/decorator.spec.ts
Expand Up @@ -29,18 +29,6 @@ describe("using decorators", () => {
expect(typeof (component as any).bind).toBe("function"); expect(typeof (component as any).bind).toBe("function");
}); });


it("should throw an descriptive error if Object.entries is not available", () => {
const originalEntries = (Object as any).entries;

(Object as any).entries = undefined;

expect(() => {
connectTo();
}).toThrowError(/Object.entries/);

(Object as any).entries = originalEntries;
});

it("should be possible to decorate a class and assign the subscribed result to the state property", () => { it("should be possible to decorate a class and assign the subscribed result to the state property", () => {
const { initialState } = arrange(); const { initialState } = arrange();


Expand Down

0 comments on commit 8ee1156

Please sign in to comment.