-
Notifications
You must be signed in to change notification settings - Fork 16
/
express-state.express.txt
38 lines (32 loc) · 3.34 KB
/
express-state.express.txt
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
EXPRESS-STATE
VERSION ==> #Node module (1.2.0)
#Adds <script>WINDOW.NAMESPACE.STR = VAL;</script> to RES.render()
EXPRESS-STATE.extend(APP) #Init that adds APP|RES.expose() to Express
APP|RES.expose(VAL,STR[,OBJ]) #Fills APP|RES.locals with:
# - client-side vs server-side:
# - "server-side":
# - APP|RES.locals.VAR[NAMESPACE.STR] = VAL
# - NAMESPACE.STR[.STR2...] is flat index, not a real OBJ (as opposed to client-side)
# - but APP|RES.locals.VAR has a special toString() function so:
# - should be put in a <script> in template, as {{VAR}}
# - used in a template, will initialize WINDOW.NAMESPACE.STR = VAL "client-side"
# - so "server-side" APP|RES.locals.VAR == WINDOW.NAMESPACE "client-side"
# - namespaces:
# - NAMESPACE is APPVAR "state namespace" (def: none)
# - VAR is APPVAR "state local" (def: "state").
# - Can specify a specific VAR and NAMESPACE for this call with OBJ.local|namespace
# - STR can be "STR.STR2[.STR3...]":
# - submembers are created if needed
# - can override sub members of previously exposed VAL
# - VAL:
# - can be any JSON'd type but also REGEXP or FUNC, providing toString() is OK,
# e.g. no state nor native functions
# - if STR:
# - remember to HTML-escape if comes from user input
# - use {{{VAR}}} with Handlebars, not {{VAR}}, otherwise it breaks (FUNC)()
# - if OBJ:
# - lazily evaluated "client-side" when and each time APP.render(), unless
# OBJ.cache true (faster but not lazy)
# - careful: always lazily evaluated "server-side"