Skip to content

Commit

Permalink
fix: Remove usage of es2015 Array.prototype.includes (#589)
Browse files Browse the repository at this point in the history
* remove all uses of es2015 Array.includes()
  • Loading branch information
alexsasharegan authored and tmorehouse committed Jun 30, 2017
1 parent be5f834 commit b3fc095
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/components/breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<script>
import bLink from './link.vue';
import { props as linkProps } from '../mixins/link';
import arrayIncludes from '../utils/arrayIncludes';
const bLinkPropKeys = Object.keys(linkProps);
export default {
Expand Down Expand Up @@ -59,7 +61,7 @@ export default {
// so we can bind to the component
// for dynamic prop proxying
normalizedItem._linkProps = Object.keys(normalizedItem).reduce((memo, itemProp) => {
if (bLinkPropKeys.includes(itemProp)) {
if (arrayIncludes(bLinkPropKeys, itemProp)) {
memo[itemProp] = normalizedItem[itemProp];
}
Expand Down
4 changes: 3 additions & 1 deletion lib/components/form-checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
<script>
import formMixin from '../mixins/form';
import formCheckBoxMixin from '../mixins/form-checkbox';
import arrayIncludes from '../utils/arrayIncludes';
import isArray from '../utils/isArray';
export default {
mixins: [formMixin, formCheckBoxMixin],
model: {
Expand All @@ -41,7 +43,7 @@ export default {
},
computed: {
isChecked() {
return this.checked.includes(this.value);
return arrayIncludes(this.checked, this.value);
}
},
methods: {
Expand Down
5 changes: 3 additions & 2 deletions lib/components/list-group-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

<script>
import bLink from './link.vue';
import { props as originalLinkProps, computed, omitLinkProps } from '../mixins/link'
import { props as originalLinkProps, computed, omitLinkProps } from '../mixins/link';
import arrayIncludes from '../utils/arrayIncludes';
// copy link props, but exclude defaults for 'href', 'to', & 'tag'
// to ensure proper component tag computation
const linkProps = Object.assign(omitLinkProps('href', 'to'), {
Expand Down Expand Up @@ -43,7 +44,7 @@ export default {
// this previously could return a string,
// coercing to a boolean for more consistent expected value
return !!(this.action || this.to || this.href || actionTags.includes(this.tag));
return !!(this.action || this.to || this.href || arrayIncludes(actionTags, this.tag));
},
listState() {
Expand Down
5 changes: 3 additions & 2 deletions lib/mixins/link.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import warn from '../utils/warn';
import arrayIncludes from '../utils/arrayIncludes';
// Props compatible with vue-router
// https://github.com/vuejs/vue-router/blob/dev/src/components/link.js
export const props = {
Expand Down Expand Up @@ -151,7 +152,7 @@ export default {

export function pickLinkProps(...propsToPick) {
return Object.keys(props).reduce((memo, prop) => {
if (propsToPick.includes(prop)) {
if (arrayIncludes(propsToPick, prop)) {
memo[prop] = props[prop];
}

Expand All @@ -161,7 +162,7 @@ export function pickLinkProps(...propsToPick) {

export function omitLinkProps(...propsToOmit) {
return Object.keys(props).reduce((memo, prop) => {
if (!propsToOmit.includes(prop)) {
if (!arrayIncludes(propsToOmit, prop)) {
memo[prop] = props[prop];
}

Expand Down
3 changes: 3 additions & 0 deletions lib/utils/arrayIncludes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function arrayIncludes(array, value) {
return array.indexOf(value) !== -1
}

0 comments on commit b3fc095

Please sign in to comment.