⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact d8bd84e66fec825ea4433ea3f83cd3f8b4c27f36b2398546c2f6a56a4a1a690a:


0000: 69 6d 70 6f 72 74 20 72 65 6d 6f 76 65 41 74 74  import removeAtt
0010: 72 69 62 75 74 65 20 66 72 6f 6d 20 27 2e 2f 2e  ribute from './.
0020: 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 64 6f  ./common/util/do
0030: 6d 2f 72 65 6d 6f 76 65 2d 61 74 74 72 69 62 75  m/remove-attribu
0040: 74 65 27 0a 69 6d 70 6f 72 74 20 63 72 65 61 74  te'.import creat
0050: 65 50 6c 61 63 68 6f 6c 64 65 72 20 66 72 6f 6d  ePlacholder from
0060: 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75 74   './../common/ut
0070: 69 6c 2f 64 6f 6d 2f 63 72 65 61 74 65 2d 70 6c  il/dom/create-pl
0080: 61 63 65 68 6f 6c 64 65 72 27 0a 69 6d 70 6f 72  aceholder'.impor
0090: 74 20 75 6e 6d 6f 75 6e 74 41 6c 6c 20 66 72 6f  t unmountAll fro
00a0: 6d 20 27 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 75  m './../common/u
00b0: 74 69 6c 2f 74 61 67 73 2f 75 6e 6d 6f 75 6e 74  til/tags/unmount
00c0: 2d 61 6c 6c 27 0a 69 6d 70 6f 72 74 20 65 78 74  -all'.import ext
00d0: 65 6e 64 20 66 72 6f 6d 20 27 2e 2f 2e 2e 2f 63  end from './../c
00e0: 6f 6d 6d 6f 6e 2f 75 74 69 6c 2f 6d 69 73 63 2f  ommon/util/misc/
00f0: 65 78 74 65 6e 64 27 0a 69 6d 70 6f 72 74 20 7b  extend'.import {
0100: 20 74 6d 70 6c 20 7d 20 66 72 6f 6d 20 27 72 69   tmpl } from 'ri
0110: 6f 74 2d 74 6d 70 6c 27 0a 69 6d 70 6f 72 74 20  ot-tmpl'.import 
0120: 7b 20 43 4f 4e 44 49 54 49 4f 4e 41 4c 5f 44 49  { CONDITIONAL_DI
0130: 52 45 43 54 49 56 45 20 7d 20 66 72 6f 6d 20 27  RECTIVE } from '
0140: 2e 2f 2e 2e 2f 63 6f 6d 6d 6f 6e 2f 67 6c 6f 62  ./../common/glob
0150: 61 6c 2d 76 61 72 69 61 62 6c 65 73 27 0a 69 6d  al-variables'.im
0160: 70 6f 72 74 20 7b 20 70 61 72 73 65 45 78 70 72  port { parseExpr
0170: 65 73 73 69 6f 6e 73 20 7d 20 66 72 6f 6d 20 27  essions } from '
0180: 2e 2f 70 61 72 73 65 27 0a 69 6d 70 6f 72 74 20  ./parse'.import 
0190: 75 70 64 61 74 65 41 6c 6c 45 78 70 72 65 73 73  updateAllExpress
01a0: 69 6f 6e 73 20 66 72 6f 6d 20 27 2e 2f 75 70 64  ions from './upd
01b0: 61 74 65 27 0a 0a 65 78 70 6f 72 74 20 64 65 66  ate'..export def
01c0: 61 75 6c 74 20 7b 0a 20 20 69 6e 69 74 28 64 6f  ault {.  init(do
01d0: 6d 2c 20 74 61 67 2c 20 65 78 70 72 29 20 7b 0a  m, tag, expr) {.
01e0: 20 20 20 20 72 65 6d 6f 76 65 41 74 74 72 69 62      removeAttrib
01f0: 75 74 65 28 64 6f 6d 2c 20 43 4f 4e 44 49 54 49  ute(dom, CONDITI
0200: 4f 4e 41 4c 5f 44 49 52 45 43 54 49 56 45 29 0a  ONAL_DIRECTIVE).
0210: 20 20 20 20 65 78 74 65 6e 64 28 74 68 69 73 2c      extend(this,
0220: 20 7b 20 74 61 67 2c 20 65 78 70 72 2c 20 73 74   { tag, expr, st
0230: 75 62 3a 20 63 72 65 61 74 65 50 6c 61 63 68 6f  ub: createPlacho
0240: 6c 64 65 72 28 29 2c 20 70 72 69 73 74 69 6e 65  lder(), pristine
0250: 3a 20 64 6f 6d 20 7d 29 0a 20 20 20 20 63 6f 6e  : dom }).    con
0260: 73 74 20 70 20 3d 20 64 6f 6d 2e 70 61 72 65 6e  st p = dom.paren
0270: 74 4e 6f 64 65 0a 20 20 20 20 70 2e 69 6e 73 65  tNode.    p.inse
0280: 72 74 42 65 66 6f 72 65 28 74 68 69 73 2e 73 74  rtBefore(this.st
0290: 75 62 2c 20 64 6f 6d 29 0a 20 20 20 20 70 2e 72  ub, dom).    p.r
02a0: 65 6d 6f 76 65 43 68 69 6c 64 28 64 6f 6d 29 0a  emoveChild(dom).
02b0: 0a 20 20 20 20 72 65 74 75 72 6e 20 74 68 69 73  .    return this
02c0: 0a 20 20 7d 2c 0a 20 20 75 70 64 61 74 65 28 29  .  },.  update()
02d0: 20 7b 0a 20 20 20 20 74 68 69 73 2e 76 61 6c 75   {.    this.valu
02e0: 65 20 3d 20 74 6d 70 6c 28 74 68 69 73 2e 65 78  e = tmpl(this.ex
02f0: 70 72 2c 20 74 68 69 73 2e 74 61 67 29 0a 0a 20  pr, this.tag).. 
0300: 20 20 20 69 66 20 28 21 74 68 69 73 2e 73 74 75     if (!this.stu
0310: 62 2e 70 61 72 65 6e 74 4e 6f 64 65 29 20 72 65  b.parentNode) re
0320: 74 75 72 6e 0a 0a 20 20 20 20 69 66 20 28 74 68  turn..    if (th
0330: 69 73 2e 76 61 6c 75 65 20 26 26 20 21 74 68 69  is.value && !thi
0340: 73 2e 63 75 72 72 65 6e 74 29 20 7b 20 2f 2f 20  s.current) { // 
0350: 69 6e 73 65 72 74 0a 20 20 20 20 20 20 74 68 69  insert.      thi
0360: 73 2e 63 75 72 72 65 6e 74 20 3d 20 74 68 69 73  s.current = this
0370: 2e 70 72 69 73 74 69 6e 65 2e 63 6c 6f 6e 65 4e  .pristine.cloneN
0380: 6f 64 65 28 74 72 75 65 29 0a 20 20 20 20 20 20  ode(true).      
0390: 74 68 69 73 2e 73 74 75 62 2e 70 61 72 65 6e 74  this.stub.parent
03a0: 4e 6f 64 65 2e 69 6e 73 65 72 74 42 65 66 6f 72  Node.insertBefor
03b0: 65 28 74 68 69 73 2e 63 75 72 72 65 6e 74 2c 20  e(this.current, 
03c0: 74 68 69 73 2e 73 74 75 62 29 0a 20 20 20 20 20  this.stub).     
03d0: 20 74 68 69 73 2e 65 78 70 72 65 73 73 69 6f 6e   this.expression
03e0: 73 20 3d 20 70 61 72 73 65 45 78 70 72 65 73 73  s = parseExpress
03f0: 69 6f 6e 73 2e 61 70 70 6c 79 28 74 68 69 73 2e  ions.apply(this.
0400: 74 61 67 2c 20 5b 74 68 69 73 2e 63 75 72 72 65  tag, [this.curre
0410: 6e 74 2c 20 74 72 75 65 5d 29 0a 20 20 20 20 7d  nt, true]).    }
0420: 20 65 6c 73 65 20 69 66 20 28 21 74 68 69 73 2e   else if (!this.
0430: 76 61 6c 75 65 20 26 26 20 74 68 69 73 2e 63 75  value && this.cu
0440: 72 72 65 6e 74 29 20 7b 20 2f 2f 20 72 65 6d 6f  rrent) { // remo
0450: 76 65 0a 20 20 20 20 20 20 74 68 69 73 2e 75 6e  ve.      this.un
0460: 6d 6f 75 6e 74 28 29 0a 20 20 20 20 20 20 74 68  mount().      th
0470: 69 73 2e 63 75 72 72 65 6e 74 20 3d 20 6e 75 6c  is.current = nul
0480: 6c 0a 20 20 20 20 20 20 74 68 69 73 2e 65 78 70  l.      this.exp
0490: 72 65 73 73 69 6f 6e 73 20 3d 20 5b 5d 0a 20 20  ressions = [].  
04a0: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 74 68 69    }..    if (thi
04b0: 73 2e 76 61 6c 75 65 29 20 75 70 64 61 74 65 41  s.value) updateA
04c0: 6c 6c 45 78 70 72 65 73 73 69 6f 6e 73 2e 63 61  llExpressions.ca
04d0: 6c 6c 28 74 68 69 73 2e 74 61 67 2c 20 74 68 69  ll(this.tag, thi
04e0: 73 2e 65 78 70 72 65 73 73 69 6f 6e 73 29 0a 20  s.expressions). 
04f0: 20 7d 2c 0a 20 20 75 6e 6d 6f 75 6e 74 28 29 20   },.  unmount() 
0500: 7b 0a 20 20 20 20 69 66 20 28 74 68 69 73 2e 63  {.    if (this.c
0510: 75 72 72 65 6e 74 29 20 7b 0a 20 20 20 20 20 20  urrent) {.      
0520: 69 66 20 28 74 68 69 73 2e 63 75 72 72 65 6e 74  if (this.current
0530: 2e 5f 74 61 67 29 20 7b 0a 20 20 20 20 20 20 20  ._tag) {.       
0540: 20 74 68 69 73 2e 63 75 72 72 65 6e 74 2e 5f 74   this.current._t
0550: 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 20  ag.unmount().   
0560: 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 74 68     } else if (th
0570: 69 73 2e 63 75 72 72 65 6e 74 2e 70 61 72 65 6e  is.current.paren
0580: 74 4e 6f 64 65 29 20 7b 0a 20 20 20 20 20 20 20  tNode) {.       
0590: 20 74 68 69 73 2e 63 75 72 72 65 6e 74 2e 70 61   this.current.pa
05a0: 72 65 6e 74 4e 6f 64 65 2e 72 65 6d 6f 76 65 43  rentNode.removeC
05b0: 68 69 6c 64 28 74 68 69 73 2e 63 75 72 72 65 6e  hild(this.curren
05c0: 74 29 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  t).      }.    }
05d0: 0a 0a 20 20 20 20 75 6e 6d 6f 75 6e 74 41 6c 6c  ..    unmountAll
05e0: 28 74 68 69 73 2e 65 78 70 72 65 73 73 69 6f 6e  (this.expression
05f0: 73 20 7c 7c 20 5b 5d 29 0a 20 20 7d 0a 7d        s || []).  }.}