-
Notifications
You must be signed in to change notification settings - Fork 4
/
proptypes.coffee
68 lines (51 loc) · 1.92 KB
/
proptypes.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2015, Quixey Inc.
# All rights reserved.
#
# Licensed under the Modified BSD License found in the
# LICENSE file in the root directory of this source tree.
# NOTE:
# Using "_id: type: J.PropTypes.key" in a model definition is a useful feature
# that actually works right now.
# But all the other type stuff in J is not implemented at all, it's just
# a vague thought.
J.PropTypes =
dict: (params) ->
# TODO
elem: (componentSpec = null) ->
# TODO
func: {name: "J.PropTypes.func"}
instance: (classSpec) ->
if _.isString(classSpec)
# Instance of a J.Model
# FIXME: Doesn't work yet
# Here at definition time, J.Models[modelName]
# probably hasn't been created yet. So we'll
# just wait until validator call time.
validator = ->
# Okay, it's validator call time.
modelClass = J.models[modelName]
unless modelClass?
throw new Meteor.Error "Invalid modelName #{JSON.stringify modelName} in instanceOfModel"
$$.instance(modelClass).apply @, arguments
else
# Instance of an arbitrary JS class
list: (params) ->
# Params:
# of:
# A typeSpec to apply recursively to the elements of the list
# TODO
# J.PropTypes.key is a pseudo-propType that the
# _id fieldSpec can use to declare that it isn't
# part of the Normalized Kernel of our data model, i.e.
# the model's key() instance function computed it
# from other fields at db-insert time.
key: {name: "J.PropTypes.key"}
num: {name: "J.PropTypes.num"}
or: (typeSpecs...) ->
# TODO
str: {name: "J.PropTypes.str"}
var: {name: "J.PropTypes.var"}
# Alias all PropTypes into $$
# E.g. $$.key, $$.func, $$.num
for propTypeName, propTypeFunc of J.PropTypes
$$[propTypeName] = propTypeFunc