Skip to content

Commit

Permalink
Merge pull request #20 from alibaba-fusion/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jdkahn authored Aug 22, 2019
2 parents 984be95 + a18fac2 commit d7d2137
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
15 changes: 5 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ const initMeta = {

class Field {
static create(com, options = {}) {
return new Field(com, options);
return new this(com, options);
}

static getUseField({ useState, useMemo }) {
return function(options = {}) {
return (options = {}) => {
const [, setState] = useState();

const field = useMemo(() => {
return new Field(
{
setState,
},
options
);
}, [setState]);
const field = useMemo(() => this.create({ setState }, options), [
setState,
]);

return field;
};
Expand Down
24 changes: 20 additions & 4 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@ const FormItem = Form.Item;
/* eslint-disable react/jsx-filename-extension */
/*global describe it afterEach */
describe('field', () => {
it('should create new field with `Field.create`', function() {
const field = Field.create(this);
describe('Field.create', function() {
it('should create new field', function() {
const field = Field.create(this);

assert(!!field);
assert(Field.prototype.isPrototypeOf(field));
})

it('should have subclass prototype', function() {
class myField extends Field {
constructor(com, options = {}) {
super(com, options);
}
}
const field = myField.create(this);

assert(!!field);
assert(myField.prototype.isPrototypeOf(field));
})

assert(!!field);
assert(Field.prototype.isPrototypeOf(field));
})

describe('render', () => {
it('should support Form', function(done) {
class Demo extends React.Component {
Expand Down

0 comments on commit d7d2137

Please sign in to comment.