Added support for class (function) mixins #1800

Merged
merged 3 commits into from May 22, 2016

Projects

None yet

2 participants

@ashleybrener
Contributor
ashleybrener commented May 18, 2016 edited
  1. Have you added test(s) for your patch? If not, why not?
    No, because existing tests are failing on dev branch before I write my tests. Could I be missing dependencies?
  2. Can you provide an example of your patch in use?
    Notice how Object mixins work correctly, but class mixins do not.
  3. Is this a breaking change?
    No

Content

In the riot.mixin function:
When setting a store value with the new mixin, if the mixin is of type function (ie a class) then extend the functions prototype with the existing store value properties (or a blank object if undefined) and set the store value with the extended class (function).

@GianlucaGuarini
Member
GianlucaGuarini commented May 18, 2016 edited

could you please add a test as well..? I will be happy to merge it

@ashleybrener
Contributor

Thank you @GianlucaGuarini, am having difficulty compiling and testing on dev branch, even before I've written my tests. Have done a fresh npm install. Here's what I'm experiencing (MacOSX):

$ make
# check code style
RIOT=../../dist/riot/riot.js ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- test/runner.js -R spec


  Riot Tests
    Node/io.js
      1) require tags
      2) render tag: timer
      3) render tag: if-test
      4) render tag: attr-test
      5) render tag: loop-child
      6) render tag: loop-replace
      7) render tag: blog (using yield)
      8) tender tag: loop table
      9) render tag: simple block (using yield)
      10) render tag: yield with no html content
      11) render tag: svg loops
      12) render tag: input,option,textarea tags having expressions as value


  0 passing (54ms)
  12 failing

  1) Riot Tests Node/io.js require tags:
     Uncaught TypeError: riot.tag2 is not a function
      at Object.<anonymous> (test/tag/~custom-parsers.tag:1:139)
      at Object.require.extensions..tag (lib/server/index.js:9:714)
      at require (internal/module.js:20:19)
      at test/specs/server/node.js:22:16
      at Array.forEach (native)
      at test/specs/server/node.js:21:12
      at f (node_modules/once/once.js:17:25)
      at Glob.<anonymous> (node_modules/glob/glob.js:146:7)
      at Glob._finish (node_modules/glob/glob.js:194:8)
      at done (node_modules/glob/glob.js:179:14)
      at Glob._processReaddir2 (node_modules/glob/glob.js:431:12)
      at node_modules/glob/glob.js:368:17
      at RES (node_modules/inflight/inflight.js:23:14)
      at f (node_modules/once/once.js:17:25)
      at Glob._readdirEntries (node_modules/glob/glob.js:572:10)
      at node_modules/glob/glob.js:549:12
      at FSReqWrap.oncomplete (fs.js:117:15)

  2) Riot Tests Node/io.js render tag: timer:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:29:20)

  3) Riot Tests Node/io.js render tag: if-test:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:34:20)

  4) Riot Tests Node/io.js render tag: attr-test:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:42:24)

  5) Riot Tests Node/io.js render tag: loop-child:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:56:20)

  6) Riot Tests Node/io.js render tag: loop-replace:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:66:20)

  7) Riot Tests Node/io.js render tag: blog (using yield):
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:76:20)

  8) Riot Tests Node/io.js tender tag: loop table:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:85:20)

  9) Riot Tests Node/io.js render tag: simple block (using yield):
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:91:20)

  10) Riot Tests Node/io.js render tag: yield with no html content:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:99:20)

  11) Riot Tests Node/io.js render tag: svg loops:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:104:20)

  12) Riot Tests Node/io.js render tag: input,option,textarea tags having expressions as value:
     TypeError: Cannot read property '0' of undefined
      at Function.riot.render.tag (lib/server/index.js:9:1622)
      at Object.riot.render (lib/server/index.js:9:1048)
      at Context.<anonymous> (test/specs/server/node.js:110:20)



=============================================================================
Writing coverage object [/Users/AB/Dev/_lib/riot/coverage/coverage.json]
Writing coverage reports at [/Users/AB/Dev/_lib/riot/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 19.23% ( 90/468 )
Branches     : 5.26% ( 16/304 )
Functions    : 10.1% ( 10/99 )
Lines        : 20.62% ( 87/422 )
================================================================================
make: *** [test-mocha] Error 12
@GianlucaGuarini
Member

try with make riot

@ashleybrener
Contributor

Ahh rookie error. Tks

@ashleybrener
Contributor

@GianlucaGuarini you're good to go.

You'll notice the same test fails on master branch.

@GianlucaGuarini GianlucaGuarini merged commit 7f2866d into riot:dev May 22, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@GianlucaGuarini
Member

cool thank you @ashleybrener

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment