Skip to content

Commit 523866a

Browse files
committed
Fix re-entrance bug on events firing during constructor
1 parent 3465e28 commit 523866a

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

Build/CommonAssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
//
1616
// You can specify all the values or you can default the Revision and Build Numbers
1717
// by using the '*' as shown below:
18-
[assembly: AssemblyVersion("1.5.2")]
19-
[assembly: AssemblyFileVersion("1.5.2")]
18+
[assembly: AssemblyVersion("1.5.3")]
19+
[assembly: AssemblyFileVersion("1.5.3")]
2020
//[assembly: AssemblyInformationalVersion("1.4.5-editlyalpha2")]

Griddly/Scripts/griddly.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,27 @@
1717
this.$element = $(element);
1818
this.options = options;
1919
this.create();
20+
this.isConstructed = false;
21+
this.eventQueue = [];
22+
23+
this.triggerOrQueue = function ()
24+
{
25+
if (this.isConstructed)
26+
{
27+
arguments[0].trigger.apply(arguments[0], Array.prototype.slice.call(arguments, 1));
28+
}
29+
else
30+
{
31+
this.eventQueue[this.eventQueue.length] = arguments;
32+
}
33+
};
2034

2135
$(this.$element).find("[data-enable-on-selection=true]").addClass("disabled");
2236

2337
if (this.options.onRefresh)
2438
this.options.onRefresh(this, 0, this.options.count > this.options.pageSize ? this.options.pageSize : this.options.count, this.options.count, null);
2539

26-
this.$element.trigger("init.griddly",
40+
this.triggerOrQueue(this.$element, "init.griddly",
2741
{
2842
start: 0,
2943
pageSize: this.options.count > this.options.pageSize ? this.options.pageSize : this.options.count,
@@ -125,6 +139,8 @@
125139
}
126140

127141
}, this);
142+
143+
this.isConstructed = true;
128144
};
129145

130146
var serializeObject = function ($elements)
@@ -646,7 +662,7 @@
646662

647663
$(".griddly-filters-inline input, .griddly-filters-inline select", this.$element).on("change", $.proxy(function (event)
648664
{
649-
this.$element.trigger("filterchange.griddly", this.$element, event.target);
665+
this.triggerOrQueue(this.$element, "filterchange.griddly", this.$element, event.target);
650666

651667
if (this.options.autoRefreshOnFilter)
652668
this.refresh(true);
@@ -792,7 +808,7 @@
792808
{
793809
if (this.options.allowedFilterModes.indexOf(mode) > -1)
794810
{
795-
this.$element.trigger("setfiltermode.griddly", { mode: mode });
811+
this.triggerOrQueue(this.$element, "setfiltermode.griddly", { mode: mode });
796812

797813
var currentFilters = this.getFilterValues();
798814
var request1 = this.buildRequest();
@@ -925,7 +941,7 @@
925941
this.setFilterValue(e, filters[e.name]);
926942
}, this));
927943

928-
this.$element.trigger("setfilters.griddly", filters);
944+
this.triggerOrQueue(this.$element, "setfilters.griddly", filters);
929945

930946
this.options.autoRefreshOnFilter = true;
931947

@@ -942,7 +958,7 @@
942958

943959
this.setFilterValues(this.options.filterDefaults);
944960

945-
this.$element.trigger("resetfilters.griddly");
961+
this.triggerOrQueue(this.$element, "resetfilters.griddly");
946962

947963
this.refresh(true);
948964
},
@@ -975,7 +991,7 @@
975991

976992
refresh: function(resetPage)
977993
{
978-
this.$element.trigger("beforerefresh.griddly");
994+
this.triggerOrQueue(this.$element, "beforerefresh.griddly");
979995

980996
if (!this.options.url)
981997
{
@@ -1066,7 +1082,7 @@
10661082
$(e).prop("checked", true);
10671083
});
10681084

1069-
this.$element.trigger("refresh.griddly",
1085+
this.triggerOrQueue(this.$element, "refresh.griddly",
10701086
{
10711087
start: startRecord,
10721088
pageSize: currentPageSize,
@@ -1091,7 +1107,7 @@
10911107
window.location = url;
10921108
}
10931109

1094-
this.$element.trigger("error.griddly", { xhr: xhr, status: status, error: errorThrown });
1110+
this.triggerOrQueue(this.$element, "error.griddly", { xhr: xhr, status: status, error: errorThrown });
10951111
}, this));
10961112
},
10971113

@@ -1157,6 +1173,13 @@
11571173
var instanceOptions = $.extend({}, $.fn.griddly.defaults, options);
11581174

11591175
$(this).data('griddly', (data = new Griddly(this, instanceOptions)));
1176+
1177+
var event = data.eventQueue.pop();
1178+
while (event)
1179+
{
1180+
event[0].trigger.apply(event[0], Array.prototype.slice.call(event, 1))
1181+
event = data.eventQueue.pop();
1182+
}
11601183
}
11611184

11621185
// call griddly method

0 commit comments

Comments
 (0)