Skip to content
Permalink
Browse files

feat(polyfills): ship with object.entries polyfill

  • Loading branch information...
zewa666 committed Jun 9, 2019
1 parent 31d8b9f commit 8ee1156d04691ea5ca5011962d9abc696ce47d4c
Showing with 20 additions and 17 deletions.
  1. +5 −1 README.md
  2. +1 −0 src/aurelia-store.ts
  3. +0 −4 src/decorator.ts
  4. +14 −0 src/polyfills.ts
  5. +0 −12 test/unit/decorator.spec.ts
@@ -17,10 +17,14 @@ You can find complete documentation on setup and usage in the official [Aurelia

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

## Polyfills

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

## Platform Support

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

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>;

// const store = Container.instance.get(Store) as Store<T>;
@@ -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;
}
}
@@ -29,18 +29,6 @@ describe("using decorators", () => {
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", () => {
const { initialState } = arrange();

0 comments on commit 8ee1156

Please sign in to comment.
You can’t perform that action at this time.