Skip to content

Commit

Permalink
feat(ic-formly): change ic-formly to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Walker Leite committed Dec 22, 2017
1 parent b3c98db commit be581bd
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 28 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,10 @@

## Usage

### With [vue-loader](https://github.com/vuejs/vue-loader) or [vueify](https://github.com/vuejs/vueify)

```js
import IcFormly from 'ic-formly.vue';
import IcFormly from 'ic-formly';

Vue.component('ic-formly', IcFormly);
```

### ES6 Modules / CommonJS

```js
import IcFormly from 'ic-formly/cjs/ic-formly.min.js';
import 'ic-formly/cjs/ic-formly.min.css';

Vue.component('ic-formly', IcFormly);
Vue.use(IcFormly);
```

### UMD
Expand All @@ -42,11 +31,6 @@ Vue.component('ic-formly', IcFormly);

<script src="https://unpkg.com/vue" charset="utf-8"></script>
<script src="./umd/ic-formly.min.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="./umd/ic-formly.min.css">

<script type="text/javascript">
Vue.component('ic-formly', window.IcFormly);
</script>
```

## Build
Expand Down
4 changes: 4 additions & 0 deletions boot_doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Vue from 'vue'
import IcFormly from './src'

Vue.use(IcFormly)
2 changes: 1 addition & 1 deletion poi.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const glob = require('glob').sync;
const {name} = require('./package.json');

module.exports = {
entry: glob('./src/**/*.vue'),
entry: glob('./src'),
filename: {
js: name + '.min.js',
css: name + '.min.css',
Expand Down
6 changes: 0 additions & 6 deletions src/ic-formly/ic-formly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@

<script>
import Vue from 'vue'
import VueFormly from 'vue-formly'
import VueFormlyBootstrap from 'vue-formly-bootstrap'
import {flatten, unflatten} from 'flat'
// FIXME: Cannot parse src/ic-formly/ic-formly.vue: TypeError: _vue2.default.use is not a function
Vue.use(VueFormly);
Vue.use(VueFormlyBootstrap);
function createModel() {
let flatted = this
.$options
Expand Down
34 changes: 34 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import VueFormly from 'vue-formly'
import VueFormlyBootstrap from 'vue-formly-bootstrap'
import IcFormly from './ic-formly/ic-formly.vue';

let Formly = {
getTypes: VueFormly.getTypes,
addType: VueFormly.addType,
addValidationMessage: VueFormly.addValidationMessage,
install(Vue, options) {

// install Vueformly
VueFormly.install(Vue, options)
VueFormlyBootstrap.install(Vue, options)

// add our components
Vue.component('ic-formly', IcFormly)
}
};

//auto install
if (typeof window !== 'undefined' && window.Vue) {
setTimeout(() => console.log(window.Vue), 3000)

window.Vue.use(Formly);
//expose formly functions if auto installed
window.Vue.$formly = {
getTypes: VueFormly.getTypes,
addType: VueFormly.addType,
addValidationMessage: VueFormly.addValidationMessage
};
}


export default Formly;
3 changes: 2 additions & 1 deletion styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
},
serverPort: 6062,
require: [
'bootstrap/dist/css/bootstrap.css'
'bootstrap/dist/css/bootstrap.css',
'./boot_doc',
]
};
7 changes: 5 additions & 2 deletions test/specs/ic-formly.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Vue from 'vue'
import Formly from '@/ic-formly/ic-formly.vue'
import Formly from '@'
import FormlyCmp from '@/ic-formly/ic-formly.vue'

Vue.use(Formly)

describe('ic-formly.vue', () => {
let Constructor, vm;
Expand All @@ -24,7 +27,7 @@ describe('ic-formly.vue', () => {
}

beforeEach(done => {
Constructor = Vue.extend(Formly);
Constructor = Vue.extend(FormlyCmp);
vm = new Constructor({
propsData,
mounted: () => done(),
Expand Down

0 comments on commit be581bd

Please sign in to comment.