0000: 69 6d 70 6f 72 74 20 7b 20 69 6e 6a 65 63 74 48 import { injectH
0010: 54 4d 4c 20 7d 20 66 72 6f 6d 20 27 2e 2e 2f 2e TML } from '../.
0020: 2e 2f 2e 2e 2f 68 65 6c 70 65 72 73 2f 69 6e 64 ./../helpers/ind
0030: 65 78 27 0a 0a 64 65 73 63 72 69 62 65 28 27 4d ex'..describe('M
0040: 69 78 69 6e 27 2c 20 66 75 6e 63 74 69 6f 6e 28 ixin', function(
0050: 29 20 7b 0a 0a 20 20 63 6f 6e 73 74 20 49 64 4d ) {.. const IdM
0060: 69 78 69 6e 20 3d 20 7b 0a 20 20 20 20 67 65 74 ixin = {. get
0070: 49 64 3a 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b Id: function() {
0080: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 74 68 . return th
0090: 69 73 2e 5f 72 69 6f 74 5f 69 64 0a 20 20 20 20 is._riot_id.
00a0: 7d 0a 20 20 7d 0a 0a 20 20 63 6c 61 73 73 20 46 }. }.. class F
00b0: 75 6e 63 74 4d 69 78 69 6e 20 7b 0a 20 20 20 20 unctMixin {.
00c0: 69 6e 69 74 28 29 20 7b 0a 20 20 20 20 20 20 74 init() {. t
00d0: 68 69 73 2e 74 79 70 65 20 3d 20 27 66 75 6e 63 his.type = 'func
00e0: 27 0a 20 20 20 20 7d 0a 20 20 20 20 67 65 74 20 '. }. get
00f0: 6d 65 73 73 61 67 65 28 29 20 7b 0a 20 20 20 20 message() {.
0100: 20 20 72 65 74 75 72 6e 20 27 49 6e 69 74 69 61 return 'Initia
0110: 6c 69 7a 65 64 27 0a 20 20 20 20 7d 0a 20 20 7d lized'. }. }
0120: 0a 0a 20 20 63 6c 61 73 73 20 43 68 69 6c 64 4d .. class ChildM
0130: 69 78 69 6e 20 65 78 74 65 6e 64 73 20 46 75 6e ixin extends Fun
0140: 63 74 4d 69 78 69 6e 20 7b 7d 0a 0a 20 20 63 6f ctMixin {}.. co
0150: 6e 73 74 20 4f 70 74 73 4d 69 78 69 6e 20 3d 20 nst OptsMixin =
0160: 7b 0a 20 20 20 20 67 65 74 4f 70 74 73 3a 20 66 {. getOpts: f
0170: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 unction() {.
0180: 20 20 72 65 74 75 72 6e 20 74 68 69 73 2e 6f 70 return this.op
0190: 74 73 0a 20 20 20 20 7d 2c 0a 0a 20 20 20 20 73 ts. },.. s
01a0: 65 74 4f 70 74 73 3a 20 66 75 6e 63 74 69 6f 6e etOpts: function
01b0: 28 6f 70 74 69 6f 6e 73 2c 20 75 70 64 61 74 65 (options, update
01c0: 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 2e 6f ) {. this.o
01d0: 70 74 73 20 3d 20 6f 70 74 69 6f 6e 73 0a 0a 20 pts = options..
01e0: 20 20 20 20 20 69 66 20 28 21 75 70 64 61 74 65 if (!update
01f0: 29 20 7b 0a 20 20 20 20 20 20 20 20 74 68 69 73 ) {. this
0200: 2e 75 70 64 61 74 65 28 29 0a 20 20 20 20 20 20 .update().
0210: 7d 0a 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 }.. return
0220: 74 68 69 73 0a 20 20 20 20 7d 0a 20 20 7d 0a 0a this. }. }..
0230: 20 20 63 6f 6e 73 74 20 4d 69 78 69 6e 57 69 74 const MixinWit
0240: 68 49 6e 69 74 20 3d 20 7b 0a 20 20 20 20 69 6e hInit = {. in
0250: 69 74 3a 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b it: function() {
0260: 0a 20 20 20 20 20 20 74 68 69 73 2e 6d 65 73 73 . this.mess
0270: 61 67 65 20 3d 20 27 69 6e 69 74 69 61 6c 69 7a age = 'initializ
0280: 65 64 27 0a 20 20 20 20 7d 2c 0a 20 20 20 20 6d ed'. },. m
0290: 65 73 73 61 67 65 3a 20 27 6e 6f 74 20 79 65 74 essage: 'not yet
02a0: 27 0a 20 20 7d 0a 0a 20 20 63 6f 6e 73 74 20 67 '. }.. const g
02b0: 6c 6f 62 61 6c 4d 69 78 69 6e 20 3d 20 7b 0a 20 lobalMixin = {.
02c0: 20 20 20 69 6e 69 74 3a 20 66 75 6e 63 74 69 6f init: functio
02d0: 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 n() {. this
02e0: 2e 5f 5f 67 6c 6f 62 61 6c 41 74 74 72 5f 5f 20 .__globalAttr__
02f0: 3d 20 27 69 6e 69 74 69 61 6c 69 7a 65 64 27 0a = 'initialized'.
0300: 20 20 20 20 20 20 74 68 69 73 2e 5f 5f 6f 70 74 this.__opt
0310: 73 4b 65 79 73 5f 5f 20 3d 20 4f 62 6a 65 63 74 sKeys__ = Object
0320: 2e 6b 65 79 73 28 74 68 69 73 2e 6f 70 74 73 29 .keys(this.opts)
0330: 0a 20 20 20 20 7d 2c 0a 20 20 20 20 5f 5f 67 65 . },. __ge
0340: 74 47 6c 6f 62 61 6c 5f 5f 3a 20 66 75 6e 63 74 tGlobal__: funct
0350: 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 72 65 ion() {. re
0360: 74 75 72 6e 20 27 67 6c 6f 62 61 6c 27 0a 20 20 turn 'global'.
0370: 20 20 7d 0a 20 20 7d 0a 0a 20 20 63 6f 6e 73 74 }. }.. const
0380: 20 67 6c 6f 62 61 6c 4d 69 78 69 6e 32 20 3d 20 globalMixin2 =
0390: 7b 0a 20 20 20 20 69 6e 69 74 3a 20 66 75 6e 63 {. init: func
03a0: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 tion() {. t
03b0: 68 69 73 2e 5f 5f 67 6c 6f 62 61 6c 41 74 74 72 his.__globalAttr
03c0: 32 5f 5f 20 3d 20 27 69 6e 69 74 69 61 6c 69 7a 2__ = 'initializ
03d0: 65 64 32 27 0a 20 20 20 20 7d 2c 0a 20 20 20 20 ed2'. },.
03e0: 5f 5f 67 65 74 47 6c 6f 62 61 6c 32 5f 5f 3a 20 __getGlobal2__:
03f0: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 function() {.
0400: 20 20 20 72 65 74 75 72 6e 20 27 67 6c 6f 62 61 return 'globa
0410: 6c 32 27 0a 20 20 20 20 7d 0a 20 20 7d 0a 0a 20 l2'. }. }..
0420: 20 63 6f 6e 73 74 20 67 65 74 74 65 72 53 65 74 const getterSet
0430: 74 65 72 4d 69 78 69 6e 20 3d 20 7b 0a 20 20 20 terMixin = {.
0440: 20 5f 76 61 6c 75 65 3a 20 66 61 6c 73 65 0a 20 _value: false.
0450: 20 7d 0a 0a 20 20 4f 62 6a 65 63 74 2e 64 65 66 }.. Object.def
0460: 69 6e 65 50 72 6f 70 65 72 74 79 28 67 65 74 74 ineProperty(gett
0470: 65 72 53 65 74 74 65 72 4d 69 78 69 6e 2c 20 27 erSetterMixin, '
0480: 76 61 6c 75 65 27 2c 20 7b 0a 20 20 20 20 67 65 value', {. ge
0490: 74 3a 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a t: function() {.
04a0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 74 68 69 return thi
04b0: 73 2e 5f 76 61 6c 75 65 0a 20 20 20 20 7d 2c 0a s._value. },.
04c0: 20 20 20 20 73 65 74 3a 20 66 75 6e 63 74 69 6f set: functio
04d0: 6e 28 76 61 6c 75 65 29 20 7b 0a 20 20 20 20 20 n(value) {.
04e0: 20 74 68 69 73 2e 5f 76 61 6c 75 65 20 3d 20 76 this._value = v
04f0: 61 6c 75 65 0a 20 20 20 20 7d 0a 20 20 7d 29 0a alue. }. }).
0500: 0a 20 20 69 74 28 27 57 69 6c 6c 20 72 65 67 69 . it('Will regi
0510: 73 74 65 72 20 61 20 6d 69 78 69 6e 20 77 69 74 ster a mixin wit
0520: 68 20 67 65 74 74 65 72 2f 73 65 74 74 65 72 20 h getter/setter
0530: 66 75 6e 63 74 69 6f 6e 73 27 2c 20 66 75 6e 63 functions', func
0540: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a tion() {. inj
0550: 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d 6d 69 78 ectHTML('<my-mix
0560: 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e 3e 27 29 in></my-mixin>')
0570: 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 6d . riot.tag('m
0580: 79 2d 6d 69 78 69 6e 27 2c 20 27 3c 73 70 61 6e y-mixin', '<span
0590: 3e 73 6f 6d 65 20 74 61 67 3c 2f 73 70 61 6e 3e >some tag</span>
05a0: 27 29 0a 0a 20 20 20 20 76 61 72 20 74 61 67 20 ').. var tag
05b0: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6d 79 = riot.mount('my
05c0: 2d 6d 69 78 69 6e 27 29 5b 30 5d 0a 0a 20 20 20 -mixin')[0]..
05d0: 20 74 61 67 2e 6d 69 78 69 6e 28 67 65 74 74 65 tag.mixin(gette
05e0: 72 53 65 74 74 65 72 4d 69 78 69 6e 29 0a 0a 20 rSetterMixin)..
05f0: 20 20 20 74 61 67 2e 76 61 6c 75 65 20 3d 20 74 tag.value = t
0600: 72 75 65 0a 0a 20 20 20 20 65 78 70 65 63 74 28 rue.. expect(
0610: 74 72 75 65 29 2e 74 6f 2e 62 65 2e 65 71 75 61 true).to.be.equa
0620: 6c 28 74 61 67 2e 5f 76 61 6c 75 65 29 0a 20 20 l(tag._value).
0630: 20 20 65 78 70 65 63 74 28 74 72 75 65 29 2e 74 expect(true).t
0640: 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 76 o.be.equal(tag.v
0650: 61 6c 75 65 29 0a 0a 20 20 20 20 74 61 67 2e 75 alue).. tag.u
0660: 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 nmount(). })..
0670: 20 69 74 28 27 57 69 6c 6c 20 72 65 67 69 73 74 it('Will regist
0680: 65 72 20 61 20 6d 69 78 69 6e 20 77 68 6f 73 65 er a mixin whose
0690: 20 70 72 6f 74 6f 74 79 70 65 20 68 61 73 20 67 prototype has g
06a0: 65 74 74 65 72 2f 73 65 74 74 65 72 20 66 75 6e etter/setter fun
06b0: 63 74 69 6f 6e 73 27 2c 20 66 75 6e 63 74 69 6f ctions', functio
06c0: 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 n() {. inject
06d0: 48 54 4d 4c 28 27 3c 6d 79 2d 6d 69 78 69 6e 3e HTML('<my-mixin>
06e0: 3c 2f 6d 79 2d 6d 69 78 69 6e 3e 27 29 0a 20 20 </my-mixin>').
06f0: 20 20 72 69 6f 74 2e 74 61 67 28 27 6d 79 2d 6d riot.tag('my-m
0700: 69 78 69 6e 27 2c 20 27 3c 73 70 61 6e 3e 73 6f ixin', '<span>so
0710: 6d 65 20 74 61 67 3c 2f 73 70 61 6e 3e 27 29 0a me tag</span>').
0720: 0a 20 20 20 20 76 61 72 20 74 61 67 20 3d 20 72 . var tag = r
0730: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6d 79 2d 6d 69 iot.mount('my-mi
0740: 78 69 6e 27 29 5b 30 5d 0a 0a 20 20 20 20 76 61 xin')[0].. va
0750: 72 20 6d 69 78 69 6e 49 6e 73 74 61 6e 63 65 20 r mixinInstance
0760: 3d 20 4f 62 6a 65 63 74 2e 63 72 65 61 74 65 28 = Object.create(
0770: 67 65 74 74 65 72 53 65 74 74 65 72 4d 69 78 69 getterSetterMixi
0780: 6e 29 0a 0a 20 20 20 20 74 61 67 2e 6d 69 78 69 n).. tag.mixi
0790: 6e 28 6d 69 78 69 6e 49 6e 73 74 61 6e 63 65 29 n(mixinInstance)
07a0: 0a 0a 20 20 20 20 74 61 67 2e 76 61 6c 75 65 20 .. tag.value
07b0: 3d 20 74 72 75 65 0a 0a 20 20 20 20 65 78 70 65 = true.. expe
07c0: 63 74 28 74 72 75 65 29 2e 74 6f 2e 62 65 2e 65 ct(true).to.be.e
07d0: 71 75 61 6c 28 74 61 67 2e 5f 76 61 6c 75 65 29 qual(tag._value)
07e0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 72 75 65 . expect(true
07f0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 ).to.be.equal(ta
0800: 67 2e 76 61 6c 75 65 29 0a 0a 20 20 20 20 74 61 g.value).. ta
0810: 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 g.unmount(). })
0820: 0a 0a 20 20 69 74 28 27 57 69 6c 6c 20 72 65 67 .. it('Will reg
0830: 69 73 74 65 72 20 61 20 67 6c 6f 62 61 6c 20 6d ister a global m
0840: 69 78 69 6e 20 77 69 74 68 6f 75 74 20 6e 61 6d ixin without nam
0850: 65 20 61 6e 64 20 6d 6f 75 6e 74 20 61 20 74 61 e and mount a ta
0860: 67 20 77 69 74 68 20 67 6c 6f 62 61 6c 20 6d 69 g with global mi
0870: 78 65 64 2d 69 6e 20 61 74 74 72 69 62 75 74 65 xed-in attribute
0880: 73 20 61 6e 64 20 6d 65 74 68 6f 64 73 27 2c 20 s and methods',
0890: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 function() {.
08a0: 20 72 69 6f 74 2e 6d 69 78 69 6e 28 67 6c 6f 62 riot.mixin(glob
08b0: 61 6c 4d 69 78 69 6e 29 0a 20 20 20 20 69 6e 6a alMixin). inj
08c0: 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d 6d 69 78 ectHTML('<my-mix
08d0: 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e 3e 27 29 in></my-mixin>')
08e0: 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 6d . riot.tag('m
08f0: 79 2d 6d 69 78 69 6e 27 2c 20 27 3c 73 70 61 6e y-mixin', '<span
0900: 3e 73 6f 6d 65 20 74 61 67 3c 2f 73 70 61 6e 3e >some tag</span>
0910: 27 29 0a 0a 20 20 20 20 76 61 72 20 74 61 67 20 ').. var tag
0920: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6d 79 = riot.mount('my
0930: 2d 6d 69 78 69 6e 27 29 5b 30 5d 0a 0a 20 20 20 -mixin')[0]..
0940: 20 65 78 70 65 63 74 28 27 69 6e 69 74 69 61 6c expect('initial
0950: 69 7a 65 64 27 29 2e 74 6f 2e 62 65 2e 65 71 75 ized').to.be.equ
0960: 61 6c 28 74 61 67 2e 5f 5f 67 6c 6f 62 61 6c 41 al(tag.__globalA
0970: 74 74 72 5f 5f 29 0a 20 20 20 20 65 78 70 65 63 ttr__). expec
0980: 74 28 27 67 6c 6f 62 61 6c 27 29 2e 74 6f 2e 62 t('global').to.b
0990: 65 2e 65 71 75 61 6c 28 74 61 67 2e 5f 5f 67 65 e.equal(tag.__ge
09a0: 74 47 6c 6f 62 61 6c 5f 5f 28 29 29 0a 20 20 20 tGlobal__()).
09b0: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 tag.unmount().
09c0: 20 7d 29 0a 0a 20 20 69 74 28 27 57 69 6c 6c 20 }).. it('Will
09d0: 72 65 67 69 73 74 65 72 20 6d 75 6c 74 69 70 6c register multipl
09e0: 65 20 67 6c 6f 62 61 6c 20 6d 69 78 69 6e 20 77 e global mixin w
09f0: 69 74 68 6f 75 74 20 6e 61 6d 65 20 61 6e 64 20 ithout name and
0a00: 6d 6f 75 6e 74 20 61 20 74 61 67 20 77 69 74 68 mount a tag with
0a10: 20 67 6c 6f 62 61 6c 20 6d 69 78 65 64 2d 69 6e global mixed-in
0a20: 20 61 74 74 72 69 62 75 74 65 73 20 61 6e 64 20 attributes and
0a30: 6d 65 74 68 6f 64 73 27 2c 20 66 75 6e 63 74 69 methods', functi
0a40: 6f 6e 28 29 20 7b 0a 20 20 20 20 72 69 6f 74 2e on() {. riot.
0a50: 6d 69 78 69 6e 28 67 6c 6f 62 61 6c 4d 69 78 69 mixin(globalMixi
0a60: 6e 29 0a 20 20 20 20 72 69 6f 74 2e 6d 69 78 69 n). riot.mixi
0a70: 6e 28 67 6c 6f 62 61 6c 4d 69 78 69 6e 32 29 0a n(globalMixin2).
0a80: 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 injectHTML('
0a90: 3c 6d 79 2d 6d 69 78 69 6e 3e 3c 2f 6d 79 2d 6d <my-mixin></my-m
0aa0: 69 78 69 6e 3e 27 29 0a 20 20 20 20 72 69 6f 74 ixin>'). riot
0ab0: 2e 74 61 67 28 27 6d 79 2d 6d 69 78 69 6e 27 2c .tag('my-mixin',
0ac0: 20 27 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 '<span>some tag
0ad0: 3c 2f 73 70 61 6e 3e 27 29 0a 0a 20 20 20 20 76 </span>').. v
0ae0: 61 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f ar tag = riot.mo
0af0: 75 6e 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b unt('my-mixin')[
0b00: 30 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 27 0].. expect('
0b10: 69 6e 69 74 69 61 6c 69 7a 65 64 27 29 2e 74 6f initialized').to
0b20: 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 5f 5f .be.equal(tag.__
0b30: 67 6c 6f 62 61 6c 41 74 74 72 5f 5f 29 0a 20 20 globalAttr__).
0b40: 20 20 65 78 70 65 63 74 28 27 69 6e 69 74 69 61 expect('initia
0b50: 6c 69 7a 65 64 32 27 29 2e 74 6f 2e 62 65 2e 65 lized2').to.be.e
0b60: 71 75 61 6c 28 74 61 67 2e 5f 5f 67 6c 6f 62 61 qual(tag.__globa
0b70: 6c 41 74 74 72 32 5f 5f 29 0a 20 20 20 20 65 78 lAttr2__). ex
0b80: 70 65 63 74 28 27 67 6c 6f 62 61 6c 27 29 2e 74 pect('global').t
0b90: 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 5f o.be.equal(tag._
0ba0: 5f 67 65 74 47 6c 6f 62 61 6c 5f 5f 28 29 29 0a _getGlobal__()).
0bb0: 20 20 20 20 65 78 70 65 63 74 28 27 67 6c 6f 62 expect('glob
0bc0: 61 6c 32 27 29 2e 74 6f 2e 62 65 2e 65 71 75 61 al2').to.be.equa
0bd0: 6c 28 74 61 67 2e 5f 5f 67 65 74 47 6c 6f 62 61 l(tag.__getGloba
0be0: 6c 32 5f 5f 28 29 29 0a 20 20 20 20 74 61 67 2e l2__()). tag.
0bf0: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a unmount(). })..
0c00: 20 20 69 74 28 27 57 69 6c 6c 20 72 65 67 69 73 it('Will regis
0c10: 74 65 72 20 61 20 67 6c 6f 62 61 6c 20 6d 69 78 ter a global mix
0c20: 69 6e 20 77 69 74 68 20 6e 61 6d 65 20 61 6e 64 in with name and
0c30: 20 6d 6f 75 6e 74 20 61 20 74 61 67 20 77 69 74 mount a tag wit
0c40: 68 20 67 6c 6f 62 61 6c 20 6d 69 78 65 64 2d 69 h global mixed-i
0c50: 6e 20 61 74 74 72 69 62 75 74 65 73 20 61 6e 64 n attributes and
0c60: 20 6d 65 74 68 6f 64 73 27 2c 20 66 75 6e 63 74 methods', funct
0c70: 69 6f 6e 28 29 20 7b 0a 20 20 20 20 72 69 6f 74 ion() {. riot
0c80: 2e 6d 69 78 69 6e 28 27 67 6c 6f 62 61 6c 27 2c .mixin('global',
0c90: 20 67 6c 6f 62 61 6c 4d 69 78 69 6e 2c 20 74 72 globalMixin, tr
0ca0: 75 65 29 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 ue). injectHT
0cb0: 4d 4c 28 27 3c 6d 79 2d 6d 69 78 69 6e 3e 3c 2f ML('<my-mixin></
0cc0: 6d 79 2d 6d 69 78 69 6e 3e 27 29 0a 20 20 20 20 my-mixin>').
0cd0: 72 69 6f 74 2e 74 61 67 28 27 6d 79 2d 6d 69 78 riot.tag('my-mix
0ce0: 69 6e 27 2c 20 27 3c 73 70 61 6e 3e 73 6f 6d 65 in', '<span>some
0cf0: 20 74 61 67 3c 2f 73 70 61 6e 3e 27 29 0a 0a 20 tag</span>')..
0d00: 20 20 20 76 61 72 20 74 61 67 20 3d 20 72 69 6f var tag = rio
0d10: 74 2e 6d 6f 75 6e 74 28 27 6d 79 2d 6d 69 78 69 t.mount('my-mixi
0d20: 6e 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65 n')[0].. expe
0d30: 63 74 28 27 69 6e 69 74 69 61 6c 69 7a 65 64 27 ct('initialized'
0d40: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 ).to.be.equal(ta
0d50: 67 2e 5f 5f 67 6c 6f 62 61 6c 41 74 74 72 5f 5f g.__globalAttr__
0d60: 29 0a 20 20 20 20 65 78 70 65 63 74 28 27 67 6c ). expect('gl
0d70: 6f 62 61 6c 27 29 2e 74 6f 2e 62 65 2e 65 71 75 obal').to.be.equ
0d80: 61 6c 28 74 61 67 2e 5f 5f 67 65 74 47 6c 6f 62 al(tag.__getGlob
0d90: 61 6c 5f 5f 28 29 29 0a 20 20 20 20 74 61 67 2e al__()). tag.
0da0: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a unmount(). })..
0db0: 20 20 69 74 28 27 57 69 6c 6c 20 72 65 67 69 73 it('Will regis
0dc0: 74 65 72 20 6d 75 6c 74 69 70 6c 65 20 67 6c 6f ter multiple glo
0dd0: 62 61 6c 20 6d 69 78 69 6e 20 77 69 74 68 20 6e bal mixin with n
0de0: 61 6d 65 20 61 6e 64 20 6d 6f 75 6e 74 20 61 20 ame and mount a
0df0: 74 61 67 20 77 69 74 68 20 67 6c 6f 62 61 6c 20 tag with global
0e00: 6d 69 78 65 64 2d 69 6e 20 61 74 74 72 69 62 75 mixed-in attribu
0e10: 74 65 73 20 61 6e 64 20 6d 65 74 68 6f 64 73 27 tes and methods'
0e20: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 , function() {.
0e30: 20 20 20 72 69 6f 74 2e 6d 69 78 69 6e 28 27 67 riot.mixin('g
0e40: 6c 6f 62 61 6c 27 2c 20 67 6c 6f 62 61 6c 4d 69 lobal', globalMi
0e50: 78 69 6e 2c 20 74 72 75 65 29 0a 20 20 20 20 72 xin, true). r
0e60: 69 6f 74 2e 6d 69 78 69 6e 28 27 67 6c 6f 62 61 iot.mixin('globa
0e70: 6c 32 27 2c 20 67 6c 6f 62 61 6c 4d 69 78 69 6e l2', globalMixin
0e80: 32 2c 20 74 72 75 65 29 0a 20 20 20 20 69 6e 6a 2, true). inj
0e90: 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d 6d 69 78 ectHTML('<my-mix
0ea0: 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e 3e 27 29 in></my-mixin>')
0eb0: 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 6d . riot.tag('m
0ec0: 79 2d 6d 69 78 69 6e 27 2c 20 27 3c 73 70 61 6e y-mixin', '<span
0ed0: 3e 73 6f 6d 65 20 74 61 67 3c 2f 73 70 61 6e 3e >some tag</span>
0ee0: 27 29 0a 0a 20 20 20 20 76 61 72 20 74 61 67 20 ').. var tag
0ef0: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6d 79 = riot.mount('my
0f00: 2d 6d 69 78 69 6e 27 29 5b 30 5d 0a 0a 20 20 20 -mixin')[0]..
0f10: 20 65 78 70 65 63 74 28 27 69 6e 69 74 69 61 6c expect('initial
0f20: 69 7a 65 64 27 29 2e 74 6f 2e 62 65 2e 65 71 75 ized').to.be.equ
0f30: 61 6c 28 74 61 67 2e 5f 5f 67 6c 6f 62 61 6c 41 al(tag.__globalA
0f40: 74 74 72 5f 5f 29 0a 20 20 20 20 65 78 70 65 63 ttr__). expec
0f50: 74 28 27 69 6e 69 74 69 61 6c 69 7a 65 64 32 27 t('initialized2'
0f60: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 ).to.be.equal(ta
0f70: 67 2e 5f 5f 67 6c 6f 62 61 6c 41 74 74 72 32 5f g.__globalAttr2_
0f80: 5f 29 0a 20 20 20 20 65 78 70 65 63 74 28 27 67 _). expect('g
0f90: 6c 6f 62 61 6c 27 29 2e 74 6f 2e 62 65 2e 65 71 lobal').to.be.eq
0fa0: 75 61 6c 28 74 61 67 2e 5f 5f 67 65 74 47 6c 6f ual(tag.__getGlo
0fb0: 62 61 6c 5f 5f 28 29 29 0a 20 20 20 20 65 78 70 bal__()). exp
0fc0: 65 63 74 28 27 67 6c 6f 62 61 6c 32 27 29 2e 74 ect('global2').t
0fd0: 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 5f o.be.equal(tag._
0fe0: 5f 67 65 74 47 6c 6f 62 61 6c 32 5f 5f 28 29 29 _getGlobal2__())
0ff0: 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 . tag.unmount
1000: 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 57 (). }).. it('W
1010: 69 6c 6c 20 6d 6f 75 6e 74 20 61 20 74 61 67 20 ill mount a tag
1020: 61 6e 64 20 70 72 6f 76 69 64 65 20 6d 69 78 65 and provide mixe
1030: 64 2d 69 6e 20 6d 65 74 68 6f 64 73 27 2c 20 66 d-in methods', f
1040: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 unction() {..
1050: 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6d 79 injectHTML('<my
1060: 2d 6d 69 78 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 -mixin></my-mixi
1070: 6e 3e 27 29 0a 0a 20 20 20 20 72 69 6f 74 2e 74 n>').. riot.t
1080: 61 67 28 27 6d 79 2d 6d 69 78 69 6e 27 2c 20 27 ag('my-mixin', '
1090: 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 3c 2f <span>some tag</
10a0: 73 70 61 6e 3e 27 2c 20 66 75 6e 63 74 69 6f 6e span>', function
10b0: 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 2e () {. this.
10c0: 6d 69 78 69 6e 28 49 64 4d 69 78 69 6e 29 0a 20 mixin(IdMixin).
10d0: 20 20 20 7d 29 0a 0a 20 20 20 20 76 61 72 20 74 }).. var t
10e0: 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 ag = riot.mount(
10f0: 27 6d 79 2d 6d 69 78 69 6e 27 29 5b 30 5d 0a 0a 'my-mixin')[0]..
1100: 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e 5f expect(tag._
1110: 72 69 6f 74 5f 69 64 29 2e 74 6f 2e 62 65 2e 65 riot_id).to.be.e
1120: 71 75 61 6c 28 74 61 67 2e 67 65 74 49 64 28 29 qual(tag.getId()
1130: 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e ). tag.unmoun
1140: 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 t(). }).. it('
1150: 57 69 6c 6c 20 6d 6f 75 6e 74 20 61 20 74 61 67 Will mount a tag
1160: 20 61 6e 64 20 70 72 6f 76 69 64 65 20 6d 69 78 and provide mix
1170: 65 64 2d 69 6e 20 6d 65 74 68 6f 64 73 20 66 72 ed-in methods fr
1180: 6f 6d 20 61 6e 20 66 75 6e 63 74 69 6f 6e 20 63 om an function c
1190: 6f 6e 73 74 72 75 63 74 6f 72 20 69 6e 73 74 61 onstructor insta
11a0: 6e 63 65 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 nce', function()
11b0: 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d {. injectHTM
11c0: 4c 28 27 3c 6d 79 2d 6d 69 78 69 6e 3e 3c 2f 6d L('<my-mixin></m
11d0: 79 2d 6d 69 78 69 6e 3e 27 29 0a 0a 20 20 20 20 y-mixin>')..
11e0: 66 75 6e 63 74 69 6f 6e 20 52 6f 6f 74 4d 69 78 function RootMix
11f0: 69 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 in() {. thi
1200: 73 2e 67 65 74 52 6f 6f 74 20 3d 20 66 75 6e 63 s.getRoot = func
1210: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 20 tion() {.
1220: 20 72 65 74 75 72 6e 20 74 68 69 73 2e 72 6f 6f return this.roo
1230: 74 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a t. }. }.
1240: 0a 20 20 20 20 76 61 72 20 72 6f 6f 74 6d 69 78 . var rootmix
1250: 69 6e 20 3d 20 6e 65 77 20 52 6f 6f 74 4d 69 78 in = new RootMix
1260: 69 6e 28 29 0a 0a 20 20 20 20 72 69 6f 74 2e 74 in().. riot.t
1270: 61 67 28 27 6d 79 2d 6d 69 78 69 6e 27 2c 20 27 ag('my-mixin', '
1280: 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 3c 2f <span>some tag</
1290: 73 70 61 6e 3e 27 2c 20 66 75 6e 63 74 69 6f 6e span>', function
12a0: 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 2e () {. this.
12b0: 6d 69 78 69 6e 28 72 6f 6f 74 6d 69 78 69 6e 29 mixin(rootmixin)
12c0: 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 76 61 72 . }).. var
12d0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e tag = riot.moun
12e0: 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b 30 5d t('my-mixin')[0]
12f0: 0a 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 .. expect(tag
1300: 2e 72 6f 6f 74 29 2e 74 6f 2e 62 65 2e 65 71 75 .root).to.be.equ
1310: 61 6c 28 74 61 67 2e 67 65 74 52 6f 6f 74 28 29 al(tag.getRoot()
1320: 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e ). tag.unmoun
1330: 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 t(). }).. it('
1340: 57 69 6c 6c 20 6d 6f 75 6e 74 20 74 77 6f 20 74 Will mount two t
1350: 61 67 73 2c 20 65 61 63 68 20 68 61 76 69 6e 67 ags, each having
1360: 20 73 65 70 61 72 61 74 65 20 6d 69 78 2d 69 6e separate mix-in
1370: 20 6d 65 74 68 6f 64 73 27 2c 20 66 75 6e 63 74 methods', funct
1380: 69 6f 6e 28 29 20 7b 0a 0a 20 20 20 20 69 6e 6a ion() {.. inj
1390: 65 63 74 48 54 4d 4c 28 5b 0a 20 20 20 20 20 20 ectHTML([.
13a0: 27 3c 6d 79 2d 6d 69 78 69 6e 32 20 69 64 3d 22 '<my-mixin2 id="
13b0: 6f 6e 65 22 3e 3c 2f 6d 79 2d 6d 69 78 69 6e 32 one"></my-mixin2
13c0: 3e 27 2c 0a 20 20 20 20 20 20 27 3c 6d 79 2d 6d >',. '<my-m
13d0: 69 78 69 6e 32 20 69 64 3d 22 74 77 6f 22 3e 3c ixin2 id="two"><
13e0: 2f 6d 79 2d 6d 69 78 69 6e 32 3e 27 0a 20 20 20 /my-mixin2>'.
13f0: 20 5d 29 0a 0a 20 20 20 20 72 69 6f 74 2e 74 61 ]).. riot.ta
1400: 67 28 27 6d 79 2d 6d 69 78 69 6e 32 27 2c 20 27 g('my-mixin2', '
1410: 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 3c 2f <span>some tag</
1420: 73 70 61 6e 3e 27 2c 20 66 75 6e 63 74 69 6f 6e span>', function
1430: 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 2e () {. this.
1440: 6d 69 78 69 6e 28 49 64 4d 69 78 69 6e 29 0a 20 mixin(IdMixin).
1450: 20 20 20 7d 29 0a 0a 20 20 20 20 76 61 72 20 66 }).. var f
1460: 69 72 73 74 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e irst = riot.moun
1470: 74 28 27 23 6f 6e 65 27 29 5b 30 5d 2c 0a 20 20 t('#one')[0],.
1480: 20 20 20 20 73 65 63 6f 6e 64 20 3d 20 72 69 6f second = rio
1490: 74 2e 6d 6f 75 6e 74 28 27 23 74 77 6f 27 29 5b t.mount('#two')[
14a0: 30 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 66 0].. expect(f
14b0: 69 72 73 74 2e 5f 72 69 6f 74 5f 69 64 29 2e 74 irst._riot_id).t
14c0: 6f 2e 62 65 2e 65 71 75 61 6c 28 66 69 72 73 74 o.be.equal(first
14d0: 2e 67 65 74 49 64 28 29 29 0a 20 20 20 20 65 78 .getId()). ex
14e0: 70 65 63 74 28 73 65 63 6f 6e 64 2e 5f 72 69 6f pect(second._rio
14f0: 74 5f 69 64 29 2e 74 6f 2e 62 65 2e 65 71 75 61 t_id).to.be.equa
1500: 6c 28 73 65 63 6f 6e 64 2e 67 65 74 49 64 28 29 l(second.getId()
1510: 29 0a 20 20 20 20 65 78 70 65 63 74 28 66 69 72 ). expect(fir
1520: 73 74 2e 5f 72 69 6f 74 5f 69 64 29 2e 6e 6f 74 st._riot_id).not
1530: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 73 65 63 .to.be.equal(sec
1540: 6f 6e 64 2e 5f 72 69 6f 74 5f 69 64 29 0a 20 20 ond._riot_id).
1550: 20 20 65 78 70 65 63 74 28 66 69 72 73 74 2e 67 expect(first.g
1560: 65 74 49 64 28 29 29 2e 6e 6f 74 2e 74 6f 2e 62 etId()).not.to.b
1570: 65 2e 65 71 75 61 6c 28 73 65 63 6f 6e 64 2e 67 e.equal(second.g
1580: 65 74 49 64 28 29 29 0a 20 20 20 20 66 69 72 73 etId()). firs
1590: 74 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 20 20 t.unmount().
15a0: 73 65 63 6f 6e 64 2e 75 6e 6d 6f 75 6e 74 28 29 second.unmount()
15b0: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 4f 70 74 . }).. it('Opt
15c0: 69 6f 6e 73 20 73 68 6f 75 6c 64 20 62 65 20 61 ions should be a
15d0: 76 61 69 6c 61 62 6c 65 20 61 6c 73 6f 20 69 6e vailable also in
15e0: 20 74 68 65 20 22 69 6e 69 74 22 20 6d 65 74 68 the "init" meth
15f0: 6f 64 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 od', function()
1600: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c {. injectHTML
1610: 28 27 3c 6d 79 2d 6d 69 78 69 6e 20 62 61 7a 3d ('<my-mixin baz=
1620: 22 62 61 7a 22 3e 3c 2f 6d 79 2d 6d 69 78 69 6e "baz"></my-mixin
1630: 3e 27 29 0a 0a 20 20 20 20 72 69 6f 74 2e 74 61 >').. riot.ta
1640: 67 28 27 6d 79 2d 6d 69 78 69 6e 27 2c 20 27 3c g('my-mixin', '<
1650: 70 3e 66 6f 6f 3c 2f 70 3e 27 29 0a 0a 20 20 20 p>foo</p>')..
1660: 20 63 6f 6e 73 74 20 74 61 67 20 3d 20 72 69 6f const tag = rio
1670: 74 2e 6d 6f 75 6e 74 28 27 6d 79 2d 6d 69 78 69 t.mount('my-mixi
1680: 6e 27 2c 20 7b 20 66 6f 6f 3a 20 27 66 6f 6f 27 n', { foo: 'foo'
1690: 2c 20 62 61 72 3a 20 27 62 61 72 27 7d 29 5b 30 , bar: 'bar'})[0
16a0: 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 ].. expect(ta
16b0: 67 2e 5f 5f 6f 70 74 73 4b 65 79 73 5f 5f 29 2e g.__optsKeys__).
16c0: 74 6f 2e 62 65 2e 64 65 65 70 2e 65 71 75 61 6c to.be.deep.equal
16d0: 28 5b 27 66 6f 6f 27 2c 20 27 62 61 72 27 2c 20 (['foo', 'bar',
16e0: 27 62 61 7a 27 5d 29 0a 20 20 20 20 74 61 67 2e 'baz']). tag.
16f0: 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a unmount(). })..
1700: 20 20 69 74 28 27 57 69 6c 6c 20 6d 6f 75 6e 74 it('Will mount
1710: 20 61 20 74 61 67 20 77 69 74 68 20 6d 75 6c 74 a tag with mult
1720: 69 70 6c 65 20 6d 69 78 69 6e 73 20 6d 69 78 65 iple mixins mixe
1730: 64 2d 69 6e 27 2c 20 66 75 6e 63 74 69 6f 6e 28 d-in', function(
1740: 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 ) {. injectHT
1750: 4d 4c 28 27 3c 6d 79 2d 6d 69 78 69 6e 3e 3c 2f ML('<my-mixin></
1760: 6d 79 2d 6d 69 78 69 6e 3e 27 29 0a 0a 20 20 20 my-mixin>')..
1770: 20 72 69 6f 74 2e 74 61 67 28 27 6d 79 2d 6d 69 riot.tag('my-mi
1780: 78 69 6e 27 2c 20 27 3c 73 70 61 6e 3e 73 6f 6d xin', '<span>som
1790: 65 20 74 61 67 3c 2f 73 70 61 6e 3e 27 2c 20 66 e tag</span>', f
17a0: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 unction() {.
17b0: 20 20 74 68 69 73 2e 6d 69 78 69 6e 28 49 64 4d this.mixin(IdM
17c0: 69 78 69 6e 2c 20 4f 70 74 73 4d 69 78 69 6e 29 ixin, OptsMixin)
17d0: 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 76 61 72 . }).. var
17e0: 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 6e tag = riot.moun
17f0: 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b 30 5d t('my-mixin')[0]
1800: 2c 0a 20 20 20 20 20 20 6e 65 77 4f 70 74 73 20 ,. newOpts
1810: 3d 20 7b 0a 20 20 20 20 20 20 20 20 27 73 6f 6d = {. 'som
1820: 65 27 3a 20 27 6f 70 74 69 6f 6e 27 2c 0a 20 20 e': 'option',.
1830: 20 20 20 20 20 20 27 76 61 6c 75 65 27 3a 20 4d 'value': M
1840: 61 74 68 2e 72 61 6e 64 6f 6d 28 29 0a 20 20 20 ath.random().
1850: 20 20 20 7d 0a 0a 20 20 20 20 65 78 70 65 63 74 }.. expect
1860: 28 74 61 67 2e 5f 72 69 6f 74 5f 69 64 29 2e 74 (tag._riot_id).t
1870: 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 67 o.be.equal(tag.g
1880: 65 74 49 64 28 29 29 0a 20 20 20 20 65 78 70 65 etId()). expe
1890: 63 74 28 74 61 67 2e 6f 70 74 73 29 2e 74 6f 2e ct(tag.opts).to.
18a0: 62 65 2e 65 71 75 61 6c 28 74 61 67 2e 67 65 74 be.equal(tag.get
18b0: 4f 70 74 73 28 29 29 0a 20 20 20 20 74 61 67 2e Opts()). tag.
18c0: 73 65 74 4f 70 74 73 28 6e 65 77 4f 70 74 73 29 setOpts(newOpts)
18d0: 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 2e . expect(tag.
18e0: 6f 70 74 73 29 2e 74 6f 2e 62 65 2e 65 71 75 61 opts).to.be.equa
18f0: 6c 28 74 61 67 2e 67 65 74 4f 70 74 73 28 29 29 l(tag.getOpts())
1900: 0a 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e .. tag.unmoun
1910: 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 t(). }).. it('
1920: 57 69 6c 6c 20 6d 6f 75 6e 74 20 61 20 70 61 72 Will mount a par
1930: 65 6e 74 20 74 61 67 20 77 69 74 68 20 61 20 6d ent tag with a m
1940: 69 78 69 6e 20 61 6e 64 20 61 20 73 75 62 2d 74 ixin and a sub-t
1950: 61 67 20 77 74 69 68 20 61 20 6d 69 78 69 6e 27 ag wtih a mixin'
1960: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 , function() {.
1970: 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c injectHTML('<
1980: 6d 79 2d 6d 69 78 69 6e 3e 3c 2f 6d 79 2d 6d 69 my-mixin></my-mi
1990: 78 69 6e 3e 27 29 0a 0a 20 20 20 20 72 69 6f 74 xin>').. riot
19a0: 2e 74 61 67 28 27 6d 79 2d 6d 69 78 69 6e 27 2c .tag('my-mixin',
19b0: 20 27 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 '<span>some tag
19c0: 3c 2f 73 70 61 6e 3e 3c 73 75 62 2d 6d 69 78 69 </span><sub-mixi
19d0: 6e 3e 3c 2f 73 75 62 2d 6d 69 78 69 6e 3e 27 2c n></sub-mixin>',
19e0: 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 function() {.
19f0: 20 20 20 20 74 68 69 73 2e 6d 69 78 69 6e 28 49 this.mixin(I
1a00: 64 4d 69 78 69 6e 2c 20 4f 70 74 73 4d 69 78 69 dMixin, OptsMixi
1a10: 6e 29 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 72 n). }).. r
1a20: 69 6f 74 2e 74 61 67 28 27 73 75 62 2d 6d 69 78 iot.tag('sub-mix
1a30: 69 6e 27 2c 20 27 3c 73 70 61 6e 3e 73 75 62 20 in', '<span>sub
1a40: 6d 69 78 69 6e 3c 2f 73 70 61 6e 3e 27 2c 20 66 mixin</span>', f
1a50: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 unction() {.
1a60: 20 20 74 68 69 73 2e 6d 69 78 69 6e 28 49 64 4d this.mixin(IdM
1a70: 69 78 69 6e 29 0a 20 20 20 20 7d 29 0a 0a 20 20 ixin). })..
1a80: 20 20 76 61 72 20 74 61 67 20 3d 20 72 69 6f 74 var tag = riot
1a90: 2e 6d 6f 75 6e 74 28 27 6d 79 2d 6d 69 78 69 6e .mount('my-mixin
1aa0: 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65 63 ')[0].. expec
1ab0: 74 28 74 61 67 2e 5f 72 69 6f 74 5f 69 64 29 2e t(tag._riot_id).
1ac0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 61 67 2e to.be.equal(tag.
1ad0: 67 65 74 49 64 28 29 29 0a 20 20 20 20 65 78 70 getId()). exp
1ae0: 65 63 74 28 74 61 67 2e 74 61 67 73 5b 27 73 75 ect(tag.tags['su
1af0: 62 2d 6d 69 78 69 6e 27 5d 29 2e 6e 6f 74 2e 74 b-mixin']).not.t
1b00: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 75 6e 64 65 o.be.equal('unde
1b10: 66 69 6e 65 64 27 29 0a 20 20 20 20 65 78 70 65 fined'). expe
1b20: 63 74 28 74 61 67 2e 74 61 67 73 5b 27 73 75 62 ct(tag.tags['sub
1b30: 2d 6d 69 78 69 6e 27 5d 2e 5f 72 69 6f 74 5f 69 -mixin']._riot_i
1b40: 64 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 74 d).to.be.equal(t
1b50: 61 67 2e 74 61 67 73 5b 27 73 75 62 2d 6d 69 78 ag.tags['sub-mix
1b60: 69 6e 27 5d 2e 67 65 74 49 64 28 29 29 0a 20 20 in'].getId()).
1b70: 20 20 65 78 70 65 63 74 28 74 61 67 2e 67 65 74 expect(tag.get
1b80: 49 64 28 29 29 2e 6e 6f 74 2e 74 6f 2e 62 65 2e Id()).not.to.be.
1b90: 65 71 75 61 6c 28 74 61 67 2e 74 61 67 73 5b 27 equal(tag.tags['
1ba0: 73 75 62 2d 6d 69 78 69 6e 27 5d 2e 67 65 74 49 sub-mixin'].getI
1bb0: 64 28 29 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d d()). tag.unm
1bc0: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 ount(). }).. i
1bd0: 74 28 27 75 73 65 20 61 6e 64 20 69 6e 69 74 69 t('use and initi
1be0: 61 6c 69 7a 65 20 72 61 77 20 66 75 6e 63 74 69 alize raw functi
1bf0: 6f 6e 73 20 61 73 20 6d 69 78 69 6e 27 2c 20 66 ons as mixin', f
1c00: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 unction() {.
1c10: 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d injectHTML('<my-
1c20: 6d 69 78 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e mixin></my-mixin
1c30: 3e 27 29 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 >'). riot.tag
1c40: 28 27 6d 79 2d 6d 69 78 69 6e 27 2c 20 27 3c 73 ('my-mixin', '<s
1c50: 70 61 6e 3e 7b 20 6d 65 73 73 61 67 65 20 7d 3c pan>{ message }<
1c60: 2f 73 70 61 6e 3e 27 2c 20 66 75 6e 63 74 69 6f /span>', functio
1c70: 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 n() {. this
1c80: 2e 6d 69 78 69 6e 28 46 75 6e 63 74 4d 69 78 69 .mixin(FunctMixi
1c90: 6e 29 0a 20 20 20 20 7d 29 0a 20 20 20 20 76 61 n). }). va
1ca0: 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 r tag = riot.mou
1cb0: 6e 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b 30 nt('my-mixin')[0
1cc0: 5d 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 ]. expect(tag
1cd0: 2e 72 6f 6f 74 2e 69 6e 6e 65 72 48 54 4d 4c 29 .root.innerHTML)
1ce0: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 3c 73 .to.be.equal('<s
1cf0: 70 61 6e 3e 49 6e 69 74 69 61 6c 69 7a 65 64 3c pan>Initialized<
1d00: 2f 73 70 61 6e 3e 27 29 0a 20 20 20 20 65 78 70 /span>'). exp
1d10: 65 63 74 28 74 61 67 2e 74 79 70 65 29 2e 74 6f ect(tag.type).to
1d20: 2e 62 65 2e 65 71 75 61 6c 28 27 66 75 6e 63 27 .be.equal('func'
1d30: 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 6e ). tag.unmoun
1d40: 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 t(). }).. it('
1d50: 62 69 6e 64 73 20 74 68 69 73 2d 72 65 66 65 72 binds this-refer
1d60: 65 6e 63 65 20 74 6f 20 74 68 65 20 74 61 67 20 ence to the tag
1d70: 6f 62 6a 65 63 74 27 2c 20 66 75 6e 63 74 69 6f object', functio
1d80: 6e 28 29 20 7b 0a 20 20 20 20 69 6e 6a 65 63 74 n() {. inject
1d90: 48 54 4d 4c 28 27 3c 6d 79 2d 6d 69 78 69 6e 3e HTML('<my-mixin>
1da0: 3c 2f 6d 79 2d 6d 69 78 69 6e 3e 27 29 0a 0a 20 </my-mixin>')..
1db0: 20 20 20 72 69 6f 74 2e 74 61 67 28 27 6d 79 2d riot.tag('my-
1dc0: 6d 69 78 69 6e 27 2c 20 27 3c 73 70 61 6e 3e 73 mixin', '<span>s
1dd0: 6f 6d 65 20 74 61 67 20 7b 20 67 65 74 49 64 28 ome tag { getId(
1de0: 29 20 7d 3c 2f 73 70 61 6e 3e 27 2c 20 66 75 6e ) }</span>', fun
1df0: 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 ction() {.
1e00: 74 68 69 73 2e 6d 69 78 69 6e 28 49 64 4d 69 78 this.mixin(IdMix
1e10: 69 6e 29 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 in). })..
1e20: 76 61 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d var tag = riot.m
1e30: 6f 75 6e 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 ount('my-mixin')
1e40: 5b 30 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 [0].. expect(
1e50: 74 61 67 2e 72 6f 6f 74 2e 69 6e 6e 65 72 48 54 tag.root.innerHT
1e60: 4d 4c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 ML).to.be.equal(
1e70: 27 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 20 '<span>some tag
1e80: 27 20 2b 20 74 61 67 2e 5f 72 69 6f 74 5f 69 64 ' + tag._riot_id
1e90: 20 2b 20 27 3c 2f 73 70 61 6e 3e 27 29 0a 20 20 + '</span>').
1ea0: 20 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a tag.unmount().
1eb0: 20 20 7d 29 0a 0a 20 20 69 74 28 27 69 6e 69 74 }).. it('init
1ec0: 69 61 6c 69 7a 65 73 20 74 68 65 20 6d 69 78 69 ializes the mixi
1ed0: 6e 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b n', function() {
1ee0: 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c 28 . injectHTML(
1ef0: 27 3c 6d 79 2d 6d 69 78 69 6e 3e 3c 2f 6d 79 2d '<my-mixin></my-
1f00: 6d 69 78 69 6e 3e 27 29 0a 0a 20 20 20 20 72 69 mixin>').. ri
1f10: 6f 74 2e 74 61 67 28 27 6d 79 2d 6d 69 78 69 6e ot.tag('my-mixin
1f20: 27 2c 20 27 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 ', '<span>some t
1f30: 61 67 3c 2f 73 70 61 6e 3e 27 2c 20 66 75 6e 63 ag</span>', func
1f40: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 tion() {. t
1f50: 68 69 73 2e 6d 69 78 69 6e 28 4d 69 78 69 6e 57 his.mixin(MixinW
1f60: 69 74 68 49 6e 69 74 29 0a 20 20 20 20 7d 29 0a ithInit). }).
1f70: 0a 20 20 20 20 76 61 72 20 74 61 67 20 3d 20 72 . var tag = r
1f80: 69 6f 74 2e 6d 6f 75 6e 74 28 27 6d 79 2d 6d 69 iot.mount('my-mi
1f90: 78 69 6e 27 29 5b 30 5d 0a 0a 20 20 20 20 65 78 xin')[0].. ex
1fa0: 70 65 63 74 28 74 61 67 2e 6d 65 73 73 61 67 65 pect(tag.message
1fb0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 69 ).to.be.equal('i
1fc0: 6e 69 74 69 61 6c 69 7a 65 64 27 29 0a 20 20 20 nitialized').
1fd0: 20 74 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 tag.unmount().
1fe0: 20 7d 29 0a 0a 20 20 69 74 28 27 72 65 67 69 73 }).. it('regis
1ff0: 74 65 72 20 61 20 6d 69 78 69 6e 20 74 6f 20 52 ter a mixin to R
2000: 69 6f 74 20 61 6e 64 20 6c 6f 61 64 20 6d 69 78 iot and load mix
2010: 69 6e 20 74 6f 20 61 20 74 61 67 27 2c 20 66 75 in to a tag', fu
2020: 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 69 nction() {. i
2030: 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d 6d njectHTML('<my-m
2040: 69 78 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e 3e ixin></my-mixin>
2050: 27 29 0a 0a 20 20 20 20 72 69 6f 74 2e 6d 69 78 ').. riot.mix
2060: 69 6e 28 27 69 64 4d 69 78 69 6e 27 2c 20 49 64 in('idMixin', Id
2070: 4d 69 78 69 6e 29 20 2f 2f 20 72 65 67 69 73 74 Mixin) // regist
2080: 65 72 20 6d 69 78 69 6e 0a 20 20 20 20 72 69 6f er mixin. rio
2090: 74 2e 74 61 67 28 27 6d 79 2d 6d 69 78 69 6e 27 t.tag('my-mixin'
20a0: 2c 20 27 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 , '<span>some ta
20b0: 67 3c 2f 73 70 61 6e 3e 27 2c 20 66 75 6e 63 74 g</span>', funct
20c0: 69 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 74 68 ion() {. th
20d0: 69 73 2e 6d 69 78 69 6e 28 27 69 64 4d 69 78 69 is.mixin('idMixi
20e0: 6e 27 29 20 2f 2f 20 6c 6f 61 64 20 6d 69 78 69 n') // load mixi
20f0: 6e 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 76 61 n. }).. va
2100: 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 r tag = riot.mou
2110: 6e 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b 30 nt('my-mixin')[0
2120: 5d 0a 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 ].. expect(ta
2130: 67 2e 5f 72 69 6f 74 5f 69 64 29 2e 74 6f 2e 62 g._riot_id).to.b
2140: 65 2e 65 71 75 61 6c 28 74 61 67 2e 67 65 74 49 e.equal(tag.getI
2150: 64 28 29 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d d()). tag.unm
2160: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 ount(). }).. i
2170: 74 28 27 72 65 67 69 73 74 65 72 20 61 20 66 75 t('register a fu
2180: 6e 63 74 69 6f 6e 20 6d 69 78 69 6e 20 74 6f 20 nction mixin to
2190: 52 69 6f 74 20 61 6e 64 20 6c 6f 61 64 20 6d 69 Riot and load mi
21a0: 78 69 6e 20 74 6f 20 61 20 74 61 67 27 2c 20 66 xin to a tag', f
21b0: 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 unction() {.
21c0: 69 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d injectHTML('<my-
21d0: 6d 69 78 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e mixin></my-mixin
21e0: 3e 27 29 0a 0a 20 20 20 20 72 69 6f 74 2e 6d 69 >').. riot.mi
21f0: 78 69 6e 28 27 66 75 6e 63 74 4d 69 78 69 6e 27 xin('functMixin'
2200: 2c 20 46 75 6e 63 74 4d 69 78 69 6e 29 20 2f 2f , FunctMixin) //
2210: 20 72 65 67 69 73 74 65 72 20 6d 69 78 69 6e 0a register mixin.
2220: 20 20 20 20 72 69 6f 74 2e 74 61 67 28 27 6d 79 riot.tag('my
2230: 2d 6d 69 78 69 6e 27 2c 20 27 3c 73 70 61 6e 3e -mixin', '<span>
2240: 73 6f 6d 65 20 74 61 67 3c 2f 73 70 61 6e 3e 27 some tag</span>'
2250: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 , function() {.
2260: 20 20 20 20 20 74 68 69 73 2e 6d 69 78 69 6e 28 this.mixin(
2270: 27 66 75 6e 63 74 4d 69 78 69 6e 27 29 20 2f 2f 'functMixin') //
2280: 20 6c 6f 61 64 20 6d 69 78 69 6e 0a 20 20 20 20 load mixin.
2290: 7d 29 0a 0a 20 20 20 20 76 61 72 20 74 61 67 20 }).. var tag
22a0: 3d 20 72 69 6f 74 2e 6d 6f 75 6e 74 28 27 6d 79 = riot.mount('my
22b0: 2d 6d 69 78 69 6e 27 29 5b 30 5d 0a 20 20 20 20 -mixin')[0].
22c0: 65 78 70 65 63 74 28 74 61 67 2e 74 79 70 65 29 expect(tag.type)
22d0: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 66 75 .to.be.equal('fu
22e0: 6e 63 27 29 0a 20 20 20 20 74 61 67 2e 75 6e 6d nc'). tag.unm
22f0: 6f 75 6e 74 28 29 0a 20 20 7d 29 0a 0a 20 20 69 ount(). }).. i
2300: 74 28 27 72 65 67 69 73 74 65 72 20 61 20 63 68 t('register a ch
2310: 69 6c 64 20 66 75 6e 63 74 69 6f 6e 20 6d 69 78 ild function mix
2320: 69 6e 20 74 6f 20 52 69 6f 74 20 61 6e 64 20 6c in to Riot and l
2330: 6f 61 64 20 6d 69 78 69 6e 20 74 6f 20 61 20 74 oad mixin to a t
2340: 61 67 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 ag', function()
2350: 7b 0a 20 20 20 20 69 6e 6a 65 63 74 48 54 4d 4c {. injectHTML
2360: 28 27 3c 6d 79 2d 6d 69 78 69 6e 3e 3c 2f 6d 79 ('<my-mixin></my
2370: 2d 6d 69 78 69 6e 3e 27 29 0a 0a 20 20 20 20 72 -mixin>').. r
2380: 69 6f 74 2e 6d 69 78 69 6e 28 27 63 68 69 6c 64 iot.mixin('child
2390: 4d 69 78 69 6e 27 2c 20 43 68 69 6c 64 4d 69 78 Mixin', ChildMix
23a0: 69 6e 29 20 2f 2f 20 72 65 67 69 73 74 65 72 20 in) // register
23b0: 6d 69 78 69 6e 0a 20 20 20 20 72 69 6f 74 2e 74 mixin. riot.t
23c0: 61 67 28 27 6d 79 2d 6d 69 78 69 6e 27 2c 20 27 ag('my-mixin', '
23d0: 3c 73 70 61 6e 3e 73 6f 6d 65 20 74 61 67 3c 2f <span>some tag</
23e0: 73 70 61 6e 3e 27 2c 20 66 75 6e 63 74 69 6f 6e span>', function
23f0: 28 29 20 7b 0a 20 20 20 20 20 20 74 68 69 73 2e () {. this.
2400: 6d 69 78 69 6e 28 27 63 68 69 6c 64 4d 69 78 69 mixin('childMixi
2410: 6e 27 29 20 2f 2f 20 6c 6f 61 64 20 6d 69 78 69 n') // load mixi
2420: 6e 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 76 61 n. }).. va
2430: 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f 75 r tag = riot.mou
2440: 6e 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b 30 nt('my-mixin')[0
2450: 5d 0a 20 20 20 20 65 78 70 65 63 74 28 74 61 67 ]. expect(tag
2460: 2e 74 79 70 65 29 2e 74 6f 2e 62 65 2e 65 71 75 .type).to.be.equ
2470: 61 6c 28 27 66 75 6e 63 27 29 0a 20 20 20 20 74 al('func'). t
2480: 61 67 2e 75 6e 6d 6f 75 6e 74 28 29 0a 20 20 7d ag.unmount(). }
2490: 29 0a 0a 20 20 69 74 28 27 63 6c 61 73 73 20 6d ).. it('class m
24a0: 69 78 69 6e 73 20 64 6f 6e 5c 27 74 20 64 65 73 ixins don\'t des
24b0: 74 72 6f 79 20 74 68 65 20 74 61 67 20 63 6c 61 troy the tag cla
24c0: 73 73 65 73 20 5f 5f 70 72 6f 74 6f 5f 5f 27 2c sses __proto__',
24d0: 20 66 75 6e 63 74 69 6f 6e 28 64 6f 6e 65 29 20 function(done)
24e0: 7b 0a 20 20 20 20 63 6c 61 73 73 20 43 6c 61 73 {. class Clas
24f0: 73 54 61 67 20 65 78 74 65 6e 64 73 20 72 69 6f sTag extends rio
2500: 74 2e 54 61 67 20 7b 0a 20 20 20 20 20 20 2f 2f t.Tag {. //
2510: 20 6d 61 6e 64 61 74 6f 72 79 20 69 6e 20 6f 72 mandatory in or
2520: 64 65 72 20 74 6f 20 75 73 65 20 61 6e 64 20 69 der to use and i
2530: 64 65 6e 74 69 66 79 20 74 68 69 73 20 63 6f 6d dentify this com
2540: 70 6f 6e 65 6e 74 0a 20 20 20 20 20 20 67 65 74 ponent. get
2550: 20 6e 61 6d 65 28 29 20 7b 0a 20 20 20 20 20 20 name() {.
2560: 20 20 72 65 74 75 72 6e 20 27 63 6c 61 73 73 2d return 'class-
2570: 74 61 67 27 0a 20 20 20 20 20 20 7d 0a 20 20 20 tag'. }.
2580: 20 20 20 67 65 74 20 74 6d 70 6c 28 29 20 7b 0a get tmpl() {.
2590: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 27 return '
25a0: 3c 70 20 6f 6e 63 6c 69 63 6b 3d 22 7b 73 6f 6d <p onclick="{som
25b0: 65 63 6c 69 63 6b 66 75 6e 63 74 69 6f 6e 7d 22 eclickfunction}"
25c0: 3e 68 69 20 7b 20 6d 65 73 73 61 67 65 20 7d 3c >hi { message }<
25d0: 2f 70 3e 27 0a 20 20 20 20 20 20 7d 0a 20 20 20 /p>'. }.
25e0: 20 20 20 67 65 74 20 61 74 74 72 73 28 29 20 7b get attrs() {
25f0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
2600: 27 27 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 ''. }.
2610: 20 67 65 74 20 63 73 73 28 29 20 7b 0a 20 20 20 get css() {.
2620: 20 20 20 20 20 72 65 74 75 72 6e 20 27 27 0a 20 return ''.
2630: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 6f 6e 43 }. onC
2640: 72 65 61 74 65 28 29 20 7b 0a 20 20 20 20 20 20 reate() {.
2650: 20 20 74 68 69 73 2e 6d 69 78 69 6e 28 46 75 6e this.mixin(Fun
2660: 63 74 4d 69 78 69 6e 29 0a 20 20 20 20 20 20 20 ctMixin).
2670: 20 65 78 70 65 63 74 28 74 68 69 73 2e 73 6f 6d expect(this.som
2680: 65 63 6c 69 63 6b 66 75 6e 63 74 69 6f 6e 29 2e eclickfunction).
2690: 74 6f 2e 62 65 2e 61 28 27 66 75 6e 63 74 69 6f to.be.a('functio
26a0: 6e 27 29 0a 20 20 20 20 20 20 20 20 64 6f 6e 65 n'). done
26b0: 28 29 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 (). }.
26c0: 20 73 6f 6d 65 63 6c 69 63 6b 66 75 6e 63 74 69 someclickfuncti
26d0: 6f 6e 28 29 20 7b 0a 20 20 20 20 20 20 20 20 74 on() {. t
26e0: 68 69 73 2e 6d 65 73 73 61 67 65 20 3d 20 27 67 his.message = 'g
26f0: 6f 6f 64 62 79 65 27 0a 20 20 20 20 20 20 7d 0a oodbye'. }.
2700: 20 20 20 20 7d 0a 20 20 20 20 6e 65 77 20 43 6c }. new Cl
2710: 61 73 73 54 61 67 28 64 6f 63 75 6d 65 6e 74 2e assTag(document.
2720: 63 72 65 61 74 65 45 6c 65 6d 65 6e 74 28 27 64 createElement('d
2730: 69 76 27 29 29 0a 20 20 7d 29 0a 0a 20 20 69 74 iv')). }).. it
2740: 28 27 55 6e 72 65 67 69 73 74 65 72 65 64 20 6d ('Unregistered m
2750: 69 78 69 6e 73 20 77 69 6c 6c 20 74 68 72 6f 77 ixins will throw
2760: 20 61 6e 20 65 72 72 6f 72 27 2c 20 66 75 6e 63 an error', func
2770: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 65 78 70 tion() {. exp
2780: 65 63 74 28 72 69 6f 74 2e 6d 69 78 69 6e 29 2e ect(riot.mixin).
2790: 74 6f 2e 74 68 72 6f 77 28 45 72 72 6f 72 29 0a to.throw(Error).
27a0: 20 20 7d 29 0a 0a 20 20 69 74 28 27 72 69 6f 74 }).. it('riot
27b0: 20 6d 69 78 69 6e 73 20 73 68 6f 75 6c 64 20 72 mixins should r
27c0: 65 63 65 69 76 65 20 74 68 65 20 72 69 6f 74 20 eceive the riot
27d0: 6f 70 74 69 6f 6e 73 20 76 69 61 20 69 6e 69 74 options via init
27e0: 20 6d 65 74 68 6f 64 27 2c 20 66 75 6e 63 74 69 method', functi
27f0: 6f 6e 28 64 6f 6e 65 29 20 7b 0a 20 20 20 20 69 on(done) {. i
2800: 6e 6a 65 63 74 48 54 4d 4c 28 27 3c 6d 79 2d 6d njectHTML('<my-m
2810: 69 78 69 6e 3e 3c 2f 6d 79 2d 6d 69 78 69 6e 3e ixin></my-mixin>
2820: 27 29 0a 0a 20 20 20 20 72 69 6f 74 2e 6d 69 78 ').. riot.mix
2830: 69 6e 28 27 69 6e 69 74 2d 77 69 74 68 2d 6f 70 in('init-with-op
2840: 74 73 27 2c 20 7b 0a 20 20 20 20 20 20 69 6e 69 ts', {. ini
2850: 74 28 6f 70 74 73 29 20 7b 0a 20 20 20 20 20 20 t(opts) {.
2860: 20 20 65 78 70 65 63 74 28 6f 70 74 73 29 2e 74 expect(opts).t
2870: 6f 2e 62 65 2e 6e 6f 74 2e 75 6e 64 65 66 69 6e o.be.not.undefin
2880: 65 64 0a 20 20 20 20 20 20 20 20 64 6f 6e 65 28 ed. done(
2890: 29 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 29 ). }. })
28a0: 20 2f 2f 20 72 65 67 69 73 74 65 72 20 6d 69 78 // register mix
28b0: 69 6e 0a 20 20 20 20 72 69 6f 74 2e 74 61 67 28 in. riot.tag(
28c0: 27 6d 79 2d 6d 69 78 69 6e 27 2c 20 27 3c 73 70 'my-mixin', '<sp
28d0: 61 6e 3e 73 6f 6d 65 20 74 61 67 3c 2f 73 70 61 an>some tag</spa
28e0: 6e 3e 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 n>', function()
28f0: 7b 0a 20 20 20 20 20 20 74 68 69 73 2e 6d 69 78 {. this.mix
2900: 69 6e 28 27 69 6e 69 74 2d 77 69 74 68 2d 6f 70 in('init-with-op
2910: 74 73 27 29 20 2f 2f 20 6c 6f 61 64 20 6d 69 78 ts') // load mix
2920: 69 6e 0a 20 20 20 20 7d 29 0a 0a 20 20 20 20 76 in. }).. v
2930: 61 72 20 74 61 67 20 3d 20 72 69 6f 74 2e 6d 6f ar tag = riot.mo
2940: 75 6e 74 28 27 6d 79 2d 6d 69 78 69 6e 27 29 5b unt('my-mixin')[
2950: 30 5d 0a 20 20 20 20 74 61 67 2e 75 6e 6d 6f 75 0]. tag.unmou
2960: 6e 74 28 29 0a 20 20 7d 29 0a 7d 29 0a nt(). }).}).