Skip to content

Commit

Permalink
use modern methods from core-js
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored and magopian committed Jul 23, 2018
1 parent 79d189c commit 786df5d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"ajv": "^5.2.3",
"babel-runtime": "^6.26.0",
"core-js": "^2.5.7",
"lodash.topath": "^4.5.2",
"prop-types": "^15.5.8",
"setimmediate": "^1.0.5"
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"]);

/**
* 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
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 +156,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

0 comments on commit 786df5d

Please sign in to comment.