Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support old browsers without polyfills #982

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"presets": ["react", "env"],
"plugins": [
"transform-object-rest-spread",
"transform-class-properties"
"transform-class-properties",
"transform-runtime"
],
"env": {
"development": {
Expand Down
135 changes: 112 additions & 23 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
},
"dependencies": {
"ajv": "^5.2.3",
"babel-preset-env": "^1.7.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

woops, I put this in the wrong place in my last pr, should have been a devDep

"babel-runtime": "^6.26.0",
"core-js": "^2.5.7",
"lodash.topath": "^4.5.2",
"prop-types": "^15.5.8",
"setimmediate": "^1.0.5"
"prop-types": "^15.5.8"
},
"devDependencies": {
"atob": "^2.0.3",
Expand All @@ -56,6 +56,8 @@
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-class-properties": "^6.18.0",
"babel-plugin-transform-object-rest-spread": "^6.16.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.16.0",
"babel-register": "^6.18.0",
"chai": "^3.3.0",
Expand Down
1 change: 0 additions & 1 deletion playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>react-jsonschema-form playground</title>
<link rel="stylesheet" id="theme" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="//cdn.polyfill.io/v2/polyfill.min.js"></script>
</head>
<body>
<div id="app"></div>
Expand Down
1 change: 0 additions & 1 deletion playground/index.prod.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<title>react-jsonschema-form playground</title>
<link rel="stylesheet" id="theme" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="./styles.css">
<script src="//cdn.polyfill.io/v2/polyfill.min.js"></script>
</head>
<body>
<div id="app"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import includes from "core-js/library/fn/array/includes";

import UnsupportedField from "./UnsupportedField";
import {
Expand Down Expand Up @@ -203,7 +204,7 @@ class ArrayField extends Component {
if (Array.isArray(itemSchema.type)) {
// While we don't yet support composite/nullable jsonschema types, it's
// future-proof to check for requirement against these.
return !itemSchema.type.includes("null");
return !includes(itemSchema.type, "null");
}
// All non-null array item types are inherently required by design
return itemSchema.type !== "null";
Expand Down
8 changes: 3 additions & 5 deletions src/components/widgets/SelectWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import PropTypes from "prop-types";

import { asNumber } from "../../utils";

const nums = new Set(["number", "integer"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this Set be taken from core-js? Or maybe the same change as above, using the polyfilled includes from core-js.


/**
* This is a silly limitation in the DOM where option change event values are
* always retrieved as strings.
*/
function processValue({ type, items }, value) {
if (value === "") {
return undefined;
} else if (
type === "array" &&
items &&
["number", "integer"].includes(items.type)
) {
} else if (type === "array" && items && nums.has(items.type)) {
return value.map(asNumber);
} else if (type === "boolean") {
return value === "true";
Expand Down
7 changes: 3 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import "setimmediate";
import validateFormData from "./validate";
import fill from "core-js/library/fn/array/fill";

const widgetMap = {
boolean: {
Expand Down Expand Up @@ -155,9 +155,8 @@ function computeDefaults(schema, parentDefaults, definitions = {}) {
if (schema.minItems > defaultsLength) {
const defaultEntries = defaults || [];
// populate the array with the defaults
const fillerEntries = new Array(
schema.minItems - defaultsLength
).fill(
const fillerEntries = fill(
new Array(schema.minItems - defaultsLength),
computeDefaults(schema.items, schema.items.defaults, definitions)
);
// then fill up the rest with either the item default or empty, up to minItems
Expand Down