-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): use-formts setup #11
Conversation
ef83d49
to
1a53507
Compare
it("for one-element schema", () => { | ||
const schema = createFormSchema(fields => ({ | ||
stringField: fields.string(), | ||
})); | ||
|
||
expect(createInitialState(schema)).toEqual({ stringField: "" }); | ||
}); | ||
|
||
it("for one-element schema", () => { | ||
const schema = createFormSchema(fields => ({ | ||
stringField: fields.string(), | ||
})); | ||
|
||
expect(createInitialState(schema)).toEqual({ stringField: "" }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated test
}, | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe another test case test case for sth like
const schema = createFormSchema(fields => ({
arr: fields.array(fields.object({ foo: fields.string(), bar: fields.string() }))
}));
const init = { arr: [{ foo: "foo" }]}
const expectedResult = { arr: [{ foo: "foo", bar: "" }]}
assert<IsExact<typeof root, ("a" | "b" | "c")[]>>(true); | ||
|
||
const first = get(Schema.theArrayChoice.nth(0)); | ||
assert<IsExact<typeof first, "a" | "b" | "c">>(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be "a" | "b" | "c" | undefiend
?
export const isArrayDesc = <Value>( | ||
x: _DescriptorApprox_<Value> | ||
): x is _ArrayDescriptorApprox_<Value> => "nth" in x && "root" in x; | ||
|
||
export const isObjectDesc = <Value>( | ||
x: _DescriptorApprox_<Value> | ||
): x is _ObjectDescriptorApprox_<Value> => "root" in x && !("nth" in x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
}); | ||
}); | ||
|
||
describe("set", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the set implementation is really nice - it preserves Structural sharing
- meaning that we don't just deep copy the input, but only copy the stuff that was updated.
I think we could reflect that in tests, something like
const original = {
left: { a: { id: 1 }, b: { id: 2 } },
right: { a: { id: 3 }, b: { id: 4 } },
};
const updated = set(obj, "right.b.id", 10)
expect(original).not.toBe(updated)
expect(original.right).not.toBe(updated.right)
expect(original.right.b).not.toBe(updated.right.b)
expect(original.right.a).toBe(updated.right.a)
expect(original.left).toBe(updated.left)
|
||
// loose typing for helping with internal impl, as working with generic target types is impossible | ||
|
||
export type _FormSchemaApprox_<Values extends object> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't that be used in create-form-schema.ts
?
Created a basic setup for
use-formts
hook.Currently, it only constructs a scheme-shaped tree of initial values and exports simple getter and setter.
Hook is not yet connected to react.