Add ability to update globals by setting new input.

This commit is contained in:
Dylan Piercey 2017-08-24 12:37:20 -07:00
parent 76eaaf9186
commit 93eee66ee0
4 changed files with 30 additions and 1 deletions

View File

@ -483,7 +483,7 @@ this.setStateDirty('numbers');
### `this.input`
The current input for the component. Setting `this.input` will result in the component being re-rendered.
The current input for the component. Setting `this.input` will result in the component being re-rendered. If a `$global` property is set the `out.global` will also be updated during the re-render, otherwise the existing `$global` is used.
## Variables

View File

@ -437,6 +437,9 @@ Component.prototype = componentProto = {
if (this.___input === undefined) {
this.___input = newInput;
if (newInput.$global) {
this.___global = newInput.$global;
}
}
return newInput;

View File

@ -0,0 +1,6 @@
class {
}
<div key="current">
Pathname: ${out.global.pathname}
</div>

View File

@ -0,0 +1,20 @@
var expect = require('chai').expect;
module.exports = function(helpers) {
var component = helpers.mount(require('./index.marko'), {
$global: {
pathname:'/'
}
});
expect(component.getEl('current').innerHTML).to.equal('Pathname: /');
component.input = {
$global: {
pathname: '/test'
}
}
component.update();
expect(component.getEl('current').innerHTML).to.equal('Pathname: /test');
};