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?
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.
Thinking about this some more, could removing riot from require's cache fix this issue?
the riot.unregister will be available in email@example.com https://github.com/riot/riot/blob/next/riot.js#L2195-L2197
It may be necessary to also clear the cache of expressions in tmpl
@aMarCruz could you please make a pull request?
@GianlucaGuarini , now the dev branch of riot-tmpl includes the public function clearCache.
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
@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.