Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurk91 committed Sep 8, 2018
1 parent 515deaf commit 41cbb66
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
33 changes: 2 additions & 31 deletions src/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,15 @@
import Flatpickr from 'flatpickr';
// You have to import css yourself
// Events to emit, copied from flatpickr source
const includedEvents = [
'onChange',
'onClose',
'onDestroy',
'onMonthChange',
'onOpen',
'onYearChange',
];
// Let's not emit these events by default
const excludedEvents = [
'onValueUpdate',
'onDayCreate',
'onParseConfig',
'onReady',
'onPreCalendarPosition',
'onKeyDown',
];
import {includedEvents, excludedEvents} from "./events";
import {camelToKebab, cloneObject, arrayify} from "./util";
// Keep a copy of all events for later use
const allEvents = includedEvents.concat(excludedEvents);
// Passing these properties in `set()` method will cause flatpickr to trigger some callbacks
const configCallbacks = ['locale', 'showMonths'];
const camelToKebab = (string) => {
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
};
const arrayify = (obj) => {
return obj instanceof Array ? obj : [obj];
};
const cloneObject = (obj) => {
return Object.assign({}, obj);
};
export default {
name: 'flat-pickr',
props: {
Expand Down
21 changes: 21 additions & 0 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Events to emit, copied from flatpickr source
const includedEvents = [
'onChange',
'onClose',
'onDestroy',
'onMonthChange',
'onOpen',
'onYearChange',
];

// Let's not emit these events by default
const excludedEvents = [
'onValueUpdate',
'onDayCreate',
'onParseConfig',
'onReady',
'onPreCalendarPosition',
'onKeyDown',
];

export {includedEvents, excludedEvents}
13 changes: 13 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const camelToKebab = (string) => {
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
};

const arrayify = (obj) => {
return obj instanceof Array ? obj : [obj];
};

const cloneObject = (obj) => {
return Object.assign({}, obj);
};

export {camelToKebab, arrayify, cloneObject}

0 comments on commit 41cbb66

Please sign in to comment.