New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear riot tag cache to aid with testing #1875

Closed
adrianblynch opened this Issue Jul 4, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@adrianblynch

adrianblynch commented Jul 4, 2016

Issue

When unit testing tags I do something like the following:

const riot = require('riot')

// Test 1 - Render the child
const child = require('./child.tag')

const childHtml = riot.render(child)

console.log(childHtml) // Looks good
const riot = require('riot') // require caches riot.

// Test 2 - Render the parent

const parent = require('./parent.tag')

const parentHtml = riot.render(parent) // `child` is cached in riot

console.log(parentHtml) // Not what I want - See below...

In the above I want a way to not use the rendered child tag in the rendering of parent.

When child has already been rendered, the output of rendering parent is:

<parent><h1>Parent: </h1> <child><h2>I'm the child</h2></child></parent>

When what I want is:

<parent><h1>Parent: </h1> <child></child></parent>

I think what I'm asking for, is a way to clear any caching of tags in riot.

Is this possible?

Environment

  • Riot: 2.4.1
  • Node: 6.2.2
  • OS: Mac OSX 10.5.5

Possible tags

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
@adrianblynch

This comment has been minimized.

Show comment
Hide comment
@adrianblynch

adrianblynch Jul 4, 2016

I thought riot.vdom would be the thing to clear down, but in my example above, vdom remains an empty array.

My understanding is that this is populated on mount, not render.

adrianblynch commented Jul 4, 2016

I thought riot.vdom would be the thing to clear down, but in my example above, vdom remains an empty array.

My understanding is that this is populated on mount, not render.

@adrianblynch

This comment has been minimized.

Show comment
Hide comment
@adrianblynch

adrianblynch Jul 4, 2016

Thinking about this some more, could removing riot from require's cache fix this issue?

adrianblynch commented Jul 4, 2016

Thinking about this some more, could removing riot from require's cache fix this issue?

@GianlucaGuarini

This comment has been minimized.

Show comment
Hide comment
@GianlucaGuarini

GianlucaGuarini Jul 6, 2016

Member

the riot.unregister will be available in riot@3.0.0 https://github.com/riot/riot/blob/next/riot.js#L2195-L2197

Member

GianlucaGuarini commented Jul 6, 2016

the riot.unregister will be available in riot@3.0.0 https://github.com/riot/riot/blob/next/riot.js#L2195-L2197

@aMarCruz

This comment has been minimized.

Show comment
Hide comment
@aMarCruz

aMarCruz Jul 17, 2016

Member

It may be necessary to also clear the cache of expressions in tmpl

Member

aMarCruz commented Jul 17, 2016

It may be necessary to also clear the cache of expressions in tmpl

@GianlucaGuarini

This comment has been minimized.

Show comment
Hide comment
@GianlucaGuarini

GianlucaGuarini Jul 18, 2016

Member

@aMarCruz could you please make a pull request?

Member

GianlucaGuarini commented Jul 18, 2016

@aMarCruz could you please make a pull request?

@aMarCruz

This comment has been minimized.

Show comment
Hide comment
@aMarCruz

aMarCruz Jul 19, 2016

Member

@GianlucaGuarini , now the dev branch of riot-tmpl includes the public function clearCache.

Usage: tmpl.clearCache()

Member

aMarCruz commented Jul 19, 2016

@GianlucaGuarini , now the dev branch of riot-tmpl includes the public function clearCache.

Usage: tmpl.clearCache()

@GianlucaGuarini

This comment has been minimized.

Show comment
Hide comment
@GianlucaGuarini

GianlucaGuarini Jul 20, 2016

Member

thanks @aMarCruz tmpl.clearCache() seems to clear the cache of all the expressions, will it be possible to clear the cache of all the expressions bound to a specific component?
In the end https://github.com/riot/riot/blob/next/riot.js#L2195-L2197 removes the implementation only of a specific tag

Member

GianlucaGuarini commented Jul 20, 2016

thanks @aMarCruz tmpl.clearCache() seems to clear the cache of all the expressions, will it be possible to clear the cache of all the expressions bound to a specific component?
In the end https://github.com/riot/riot/blob/next/riot.js#L2195-L2197 removes the implementation only of a specific tag

@aMarCruz

This comment has been minimized.

Show comment
Hide comment
@aMarCruz

aMarCruz Aug 30, 2016

Member

@GianlucaGuarini with the current implementation clearing the cache for specific tag is not possible.
There's no link to the source, the expression byself is the hash in the cache (a plain object) and it is shared between tags.

Member

aMarCruz commented Aug 30, 2016

@GianlucaGuarini with the current implementation clearing the cache for specific tag is not possible.
There's no link to the source, the expression byself is the hash in the cache (a plain object) and it is shared between tags.

@GianlucaGuarini GianlucaGuarini added this to the 3.0.0 milestone Oct 15, 2016

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