Context | Example | Description |
Model (M) | CLASS({ package: …, name: .., … }); | Define model |
this.MyModel.create({ args }); | Instantiate in context that requires pkg.MyModel. | |
M, Feature | documentation: ‘Short description’ | Document a model, property, method, listener, action, or similar with string. |
documentation: function() {/* <p>long description of $$DOC(.)</p> */} | Document a model, property, method, listener, action, or similar with multiline string. | |
M: Properties | ‘propertyName’ | Define named property. |
{ model_: ‘StringProperty’, name: ‘str’ } | Define property typed by property’s model. Some basic models are ~Property where ~ is one of Int, Float, Boolean, StringProperty, Array, StringArray, ViewFactory, StringEnum, Reference, ReferenceArray, … | |
{ type: ‘com.google.project.Foo’, name: ‘foo’ } | Define property typed by property’s “type”. | |
M: Property | defaultValue: ‘John Smith’ | Provide static default parsed when model is parsed. |
defaultValueFn: function() { return this.first + ‘ ‘ + this.last; } | Provide default computed every time property is accessed (and default has not been overridden). | |
lazyFactory: function() { return this.first + ‘ ‘ + this.last; } | Provide factory that produces property value the first time it is accessed. (Factory does not run again after first access.). | |
factory: function() { return this.first + ‘ ‘ + this.last; } | Provide factory that produces property value when object is instantiated. (Factory does not run again after instantiation.). | |
postSet: function(old, nu) { old && old.removeListener(this.l); nu && nu.addListener(this.l); } | React to changes to the property, after the change has been made (nu will match the property’s current value). | |
getter: function() { return this.first + ‘ ‘ + this.last; } | Provide a getter that is called every time the property is accessed. Warning: This is expensive; avoid whenever possible. | |
setter: function(v) { return !!v; } | Provide a setter that is called every time the property is assigned. Warning: This is expensive; avoid whenever possible. | |
M: Methods | function methodName(args) { /* Some method documentation */ … } | Define a method named methodName, providing documentation and code only. |
{ name: ‘methodName’, description: ‘Short description’, args: [ { model_: ‘Arg1’, name: ‘arg1’, type: ‘the.arg.Type’, description: ‘Description’ }, … ], returnType: ‘the.return.Type’, code: function(args) { … } } | Provide a detailed method definition including data such as description, return type, argument specifications. | |
M: Listeners | { name: ‘onClick’, isFramed: true, code: function(event) { … } } or { name: ‘onExpensiveOperation’, isMerged: 2000, code: function(event) { … } } | Define a listener (a method pre-bound to the correct “this”). Listeners support isFramed: true to ensure that they are fired once per animation frame, or isMerged: numberOfMillis to ensure that they are fired no more frequently than numberOfMillis. |
M: Actions | { name: ‘play’, label: ‘Play Video’, help: ‘Play video for post’, iconUrl: ‘../icons/play.png’, isAvailable: function() { return this.video; }, isEnabled: function() { return this.video && !this.video.isPlaying; }, action: function() { … }, } | Define an action; i.e., a method that is run by the user interacting with the UI (e.g., clicking an action button, selecting the action from a menu, etc.). Actions support tooltips that show help text, text labels, image icons, and functions that signal whether an action is available and/or is enabled. Unavailable actions do not show up in the GUI at all. Disabled actions show up, but in a way that indicates that the action cannot be performed (e.g., “greyed out” text on an action button). Warning: Action implementations are called the “action”, not the “code” (as in methods and listeners). |
DAO Sink | { put: function(obj) { … }, remove: function(obj) { … }, error: function(args) { … }, eof: function() { … } } | Most DAO operations receive a sink. The sink may include any of these (optional) operations. put is for objects being put into a DAO, remove is for objects being deleted from a DAO, error is for responding to errors during DAO operations, and eof is called once after all put operations during a select operation. |
function() { … } | Shorthand for { put: function() { … } }. | |
M: Templates | function toHTML() {/* … */} | Template using ordinary template syntax (content is “…”). |
{ name: ‘toHTML’, template: function(out, …) { out(‘Some content’); … out(‘Some more content’); } } | Template using a custom function that invokes the template “out” function to emit content. | |
M: Template | {{simpleJSExpression}} | HTML-escaped form of given expression. |
{{{simpleJSExpression}}} | Literal (unescaped) form of given expression. Avoid this. | |
<%= complexJSExpression %> | As above, but supports better parsing of, e.g., closures. | |
%%viewProperty{ args } | Construct a view of the given view’s property name. | |
$$dataProperty{ args } | Construct a view of the given view.data’s property name. | |
<% JS Code %> | Execute inline Javascript. | |
DAO | dao.put(obj, opt_sink) | Put a single object to DAO (then to opt_sink). |
dao.remove(query, opt_sink) | Delete item(s) from DAO (then from opt_sink). | |
dao.find(primary_key, sink) | Find an object by primary key, then put it to sink. | |
dao.where(query) /*1*/ .orderBy(comparators) /*2*/ .skip(n) /*3*/ .limit(m) /*4*/ .select(sink)(function(sink){}) /*5*/ | 1, 2, 3, 4: Return DAO same as original DAO, except /*1*/ contains only objects that match query, /*2*/ orders objects by comparators, /*3*/ excludes the first n objects, or /*4*/ contains only the first m objects. Note: Storing these values allows for binding a specially decorated DAO to a view, or similar. /*5*/: For each object in DAO: sink.put(obj). Then sink.eof(). Then invoke function(sink) {}. | |
dao.listen(sink) | Listen for all sinkable updates on DAO. | |
dao.pipe(sink) | Shorthand for select-then-listen. | |
mLang (mL) | COUNT() | Decorate a sink with sink.count, a count of objects. |
mL: Compare | NEQ|EQ(a, b) | (In)equality. E.g., EQ(Person.TITLE, ‘Mr’). |
EQ_IC(a, b) | Equality, ignore-case. | |
LT|LTE|GT|GTE(a, b) | Less than (or equal to), greater than (or equal to). | |
mL: Array | IN(a, b) | Read as a is an element of b, i.e., b contains a. |
IN_EQ(a, b) | As above, but ignore-case. | |
mL: Predicate | AND(mLang1, mLang2) | Conjunction of two Boolean-producing mLangs. |
OR(mLang1, mLang2) | Disjunction of two Boolean-producing mLangs. | |
NOT(mLang) | Negate an mLang. | |
mL: Reduce | MIN(expr) | Minimum value of all expr values over all objects. |
MAX(expr) | Maximum value of all expr values over all objects. | |
SUM(expr) | Sum of all expr values over all objects. | |
AVG(expr) | Average of all expr values over all objects. | |
DISTINCT(mLang) | Filter the set of distinct values from an mLang. | |
mL: Combine | SEQ(mLang1, mLang2, …) | Group a series of values into a sequence. |
mL: Strings | CONCAT(mLang1, mLang2, …) | Concatenate string-valued mLangs. |
STARTS_WITH(mLang, prefix) | Filter string-valued mLangs that start with prefix. | |
STARTS_WITH_IC(mLang, str) | As above, but ignore-case. | |
CONTAINS(mLang, substr) | Filter string-valued mLangs that contain substr. | |
CONTAINS_IC(mLang, substr) | As above, but ignore-case. |
FOAM Cheat Sheet ()