Skip to content

Commit 369b61e

Browse files
authored
Merge pull request jbaysolutions#336 from pmorch/emit-layout-ready-later
Emit layout ready later - after GridItems have their final sizes in pixels
2 parents fd7a5c0 + 4abcf67 commit 369b61e

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/components/GridLayout.vue

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,35 +153,59 @@
153153
this.originalLayout = this.layout;
154154
const self = this;
155155
this.$nextTick(function() {
156-
if (self.width === null) {
157-
self.onWindowResize();
156+
self.onWindowResize();
158157
159-
self.initResponsiveFeatures();
158+
self.initResponsiveFeatures();
159+
160+
//self.width = self.$el.offsetWidth;
161+
addWindowEventListener('resize', self.onWindowResize);
160162
161-
//self.width = self.$el.offsetWidth;
162-
addWindowEventListener('resize', self.onWindowResize);
163-
}
164163
compact(self.layout, self.verticalCompact);
165164
166165
self.updateHeight();
167166
self.$nextTick(function () {
168167
this.erd = elementResizeDetectorMaker({
169-
strategy: "scroll" //<- For ultra performance.
168+
strategy: "scroll", //<- For ultra performance.
169+
// See https://github.com/wnr/element-resize-detector/issues/110 about callOnAdd.
170+
callOnAdd: false,
170171
});
171172
this.erd.listenTo(self.$refs.item, function () {
172173
self.onWindowResize();
173174
});
174175
});
175-
176-
self.$emit('layout-ready', self.layout);
177176
});
178177
});
179178
},
180179
watch: {
181-
width: function () {
180+
width: function (newval, oldval) {
182181
this.$nextTick(function () {
183182
//this.$broadcast("updateWidth", this.width);
184183
this.eventBus.$emit("updateWidth", this.width);
184+
if (oldval === null) {
185+
/*
186+
If oldval == null is when the width has never been
187+
set before. That only occurs when mouting is
188+
finished, and onWindowResize has been called and
189+
this.width has been changed the first time after it
190+
got set to null in the constructor. It is now time
191+
to issue layout-ready events as the GridItems have
192+
their sizes configured properly.
193+
194+
The reason for emitting the layout-ready events on
195+
the next tick is to allow for the newly-emitted
196+
updateWidth event (above) to have reached the
197+
children GridItem-s and had their effect, so we're
198+
sure that they have the final size before we emit
199+
layout-ready (for this GridLayout) and
200+
item-layout-ready (for the GridItem-s).
201+
202+
This way any client event handlers can reliably
203+
invistigate stable sizes of GridItem-s.
204+
*/
205+
this.$nextTick(() => {
206+
this.$emit('layout-ready', self.layout);
207+
});
208+
}
185209
this.updateHeight();
186210
});
187211
},

0 commit comments

Comments
 (0)