Skip to content

Commit

Permalink
Add mixin for migration of components
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmos committed Dec 28, 2017
1 parent e30e810 commit 8664f37
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/mixins/migrating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Show migrating guide in browser console.
*
* Usage:
* import Migrating from 'element-ui/src/mixins/migrating';
*
* mixins: [Migrating]
*
* add getMigratingConfig method for your component.
* getMigratingConfig() {
* return {
* props: {
* 'allow-no-selection': 'allow-no-selection is removed.',
* 'selection-mode': 'selection-mode is removed.'
* },
* events: {
* selectionchange: 'selectionchange is renamed to selection-change.'
* }
* };
* },
*/
export default {
mounted() {
if (process.env.NODE_ENV === 'production') return;
if (!this.$vnode) return;
const { props = {}, events = {} } = this.getMigratingConfig();
const { data, componentOptions } = this.$vnode;
const definedProps = data.attrs || {};
const definedEvents = componentOptions.listeners || {};

for (let propName in definedProps) {
if (definedProps.hasOwnProperty(propName) && props[propName]) {
console.warn(
`[Element Migrating][${this.$options.name}][Attribute]: ${
props[propName]
}`
);
}
}

for (let eventName in definedEvents) {
if (definedEvents.hasOwnProperty(eventName) && events[eventName]) {
console.warn(
`[Element Migrating][${this.$options.name}][Event]: ${
events[eventName]
}`
);
}
}
},

methods: {
getMigratingConfig() {
return {
props: {},
events: {},
};
},
},
};

0 comments on commit 8664f37

Please sign in to comment.