-
Notifications
You must be signed in to change notification settings - Fork 2
Schemas And Types
Justin Meyer edited this page Sep 16, 2021
·
9 revisions
Map types:
{
type: "map",
keys: {
name: MaybeString
id: MaybeNumber
}
}
List Types
{
type: "list",
values: String
keys: {
count: Number
}
}
{
// BASIC PROPERTIES
// These are used a LOT of places in CanJS.
[can.isMember](value){
return // if `value` is an instance of the type
}
[can.new](value) {
return // make an instance of the type given value
}
[can.serialize](value) {
return // an JSON.stringify() representation of the instance
}
// SET ENHANCEMENTS
// Properties on a type used to help set logic
// This type is used as the class when doing query logic comparisons.
// For example, you might want {date: "10-22"} on your observables to remain very
// string-like but you need CQL to treat that as a date.
[can.SetType]: {
// Takes the query value (Ex: "10-22")
constructor(){
}
// Turn a value like `{$gt: "10-22"}` into `new GreaterThan(new DateSet("10-22"))`
hydrate(valueToHydrate, childrenHydrator) {
return // hydrated value
}
// A Map of various set comparison operators involving the type
// It's two-levels deep to account for directionality with difference.
[can.setComparisons]: Map({
[Type1]:
{
[Type2]: {intersection(sA, sb), union(sA, sb), difference(sA, sb) }
}
})
// valueOf or toString are used to get a sortable representation used for things like GreaterThan()
valueOf(){
return // value used for comparison
}
toString(){
return // value used for comparison
}
[can.serialize]() {
return // turn this back into something that would be used by a query
}
}
}