Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
chore: adding ApiViewModel class support
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodek committed Apr 25, 2020
1 parent 2c7ac70 commit cfb7556
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
39 changes: 17 additions & 22 deletions api-form-mixin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiViewModel } from '@api-components/api-view-model-transformer';
/**
@license
Copyright 2018 The Advanced REST client authors <[email protected]>
Expand Down Expand Up @@ -266,31 +267,25 @@ export const ApiFormMixin = (base) => class extends base {
* `model`.
*
* @param {String} binding Value if the `binding` property.
* @param {Object} opts Additional options:
* - inputLabel {String} - Forces a label of the input
* @param {Object=} opts Default options for the ModelItem. See `ApiViewModel`
* for the details.
*/
addCustom(binding, opts) {
if (!opts) {
opts = {};
}
const e = new CustomEvent('api-property-model-build', {
bubbles: true,
composed: true,
cancelable: true,
detail: {
name: opts.name || '',
value: opts.value || '',
binding: binding,
schema: {
enabled: true,
isCustom: true,
inputLabel: opts.inputLabel || undefined
}
addCustom(binding, opts={}) {
const { name='', value='', inputLabel } = opts;
const defaults = {
name,
value,
binding,
schema: {
enabled: true,
isCustom: true,
inputLabel,
}
});
this.dispatchEvent(e);
};
const worker = new ApiViewModel();
const item = worker.buildProperty(defaults);
const model = this.model || [];
this.model = [...model, e.detail];
this.model = [...model, item];
this.optionalOpened = true;
}
/**
Expand Down
30 changes: 30 additions & 0 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 @@ -28,6 +28,7 @@
"email": "[email protected]"
},
"dependencies": {
"@api-components/api-view-model-transformer": "^4.1.0",
"lit-element": "^2.3.1"
},
"devDependencies": {
Expand Down
9 changes: 0 additions & 9 deletions test/api-form-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,6 @@ describe('ApiFormMixin', function() {
element.addCustom();
assert.lengthOf(element.model, 2);
});

it('Dispatches api-property-model-build event with basic data', (done) => {
element.addEventListener('api-property-model-build', (e) => {
assert.isTrue(e.cancelable, 'Event is cancelable');
assert.typeOf(e.detail, 'object');
done();
});
element.addCustom();
});
});

describe('computeIsOptional()', () => {
Expand Down

0 comments on commit cfb7556

Please sign in to comment.