mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Add ability to update globals by setting new input.
This commit is contained in:
parent
76eaaf9186
commit
93eee66ee0
@ -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
|
||||
|
||||
|
||||
@ -437,6 +437,9 @@ Component.prototype = componentProto = {
|
||||
|
||||
if (this.___input === undefined) {
|
||||
this.___input = newInput;
|
||||
if (newInput.$global) {
|
||||
this.___global = newInput.$global;
|
||||
}
|
||||
}
|
||||
|
||||
return newInput;
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
class {
|
||||
}
|
||||
|
||||
<div key="current">
|
||||
Pathname: ${out.global.pathname}
|
||||
</div>
|
||||
20
test/autotests/components-browser/input-global/test.js
Normal file
20
test/autotests/components-browser/input-global/test.js
Normal 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');
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user