#shapeshift's default with respect to surroundings
1 messages · Page 1 of 1 (latest)
s.object({
name: s.enum("A", "B"),
other: s.object({ name: s.string }).default(/** if name is "A", default is { name: "abc" }, if name is "B", default is { name: "cba" }
With actual code block
@ionic elbow might be able to answer quicker than me or @void sand
I don't think this is possible now it will be possible after adding when
I don't fully understand the question
basically if the name is "A", then the default is { name: "abc" }, if its "B", then the default is { name: "bca" }
Oh, conditional defaults
Once we implement when, You'll be able to do it like this
s.object({
name: s.enum("A", "B"),
other: s.object({ name: s.string }).when('name', {
is: (v) => v==='A',
then: (s) => s.default({name: 'abc'}),
else: (s) => s.default({name: 'bca'})
})
and the recursive object thing, what I mean is
const v = s.object({
name: "abc",
option: v
});
Iirc we do support recursivity
yeah
how do I do it tho, cuz js doesn't allow using the variable before declaration
true. In general, if anything isn't possible in js won't be possible in shapeshift too. But u can do it using lazy
oki, thanks