@@ -121,14 +121,10 @@ export default class Window extends Node {
121
121
const property = properties [ binding . name ] || binding . name ;
122
122
123
123
if ( ! events [ associatedEvent ] ) events [ associatedEvent ] = [ ] ;
124
- events [ associatedEvent ] . push (
125
- `${ binding . value . node . name } : this.${ property } `
126
- ) ;
127
-
128
- // add initial value
129
- compiler . target . metaBindings . push (
130
- `this._state.${ binding . value . node . name } = window.${ property } ;`
131
- ) ;
124
+ events [ associatedEvent ] . push ( {
125
+ name : binding . value . node . name ,
126
+ value : property
127
+ } ) ;
132
128
} ) ;
133
129
134
130
const lock = block . getUniqueName ( `window_updating` ) ;
@@ -137,13 +133,37 @@ export default class Window extends Node {
137
133
138
134
Object . keys ( events ) . forEach ( event => {
139
135
const handlerName = block . getUniqueName ( `onwindow${ event } ` ) ;
140
- const props = events [ event ] . join ( ',\n' ) ;
136
+ const props = events [ event ] ;
141
137
142
138
if ( event === 'scroll' ) {
143
139
// TODO other bidirectional bindings...
144
140
block . addVariable ( lock , 'false' ) ;
145
141
block . addVariable ( clear , `function() { ${ lock } = false; }` ) ;
146
142
block . addVariable ( timeout ) ;
143
+
144
+ const condition = [
145
+ bindings . scrollX && `"${ bindings . scrollX } " in this._state` ,
146
+ bindings . scrollY && `"${ bindings . scrollY } " in this._state`
147
+ ] . filter ( Boolean ) . join ( ' || ' ) ;
148
+
149
+ const x = bindings . scrollX && `this._state.${ bindings . scrollX } ` ;
150
+ const y = bindings . scrollY && `this._state.${ bindings . scrollY } ` ;
151
+
152
+ compiler . target . metaBindings . addBlock ( deindent `
153
+ if (${ condition } ) {
154
+ window.scrollTo(${ x || 'window.pageXOffset' } , ${ y || 'window.pageYOffset' } );
155
+ }
156
+
157
+ ${ x && `${ x } = window.pageXOffset;` }
158
+
159
+ ${ y && `${ y } = window.pageYOffset;` }
160
+ ` ) ;
161
+ } else {
162
+ props . forEach ( prop => {
163
+ compiler . target . metaBindings . addLine (
164
+ `this._state.${ prop . name } = window.${ prop . value } ;`
165
+ ) ;
166
+ } ) ;
147
167
}
148
168
149
169
const handlerBody = deindent `
@@ -154,7 +174,7 @@ export default class Window extends Node {
154
174
${ compiler . options . dev && `component._updatingReadonlyProperty = true;` }
155
175
156
176
#component.set({
157
- ${ props }
177
+ ${ props . map ( prop => ` ${ prop . name } : this. ${ prop . value } ` ) }
158
178
});
159
179
160
180
${ compiler . options . dev && `component._updatingReadonlyProperty = false;` }
0 commit comments