JSFiddle - React, Tailwind, and code Playground
by Boban Stojanovski
JavaScript
function DataModel() {
this.url = '/wherever';
}
DataModel.prototype.getData = function() {
$.ajax({
url: this.url,
context: this,
success: this.onSuccess
});
};
DataModel.prototype.onSuccess = function(data) {
$(window).trigger('DataModel:success', data);
};
var dataModel = new DataModel();
function ListView(el) {
this.$el = $(el);
this.bindEvents();
}
ListView.prototype.bindEvents = function() {
$(window).on('DataModel:success', $.proxy(this.addData, this));
};
ListView.prototype.addData = function(data) {
this.$el.append($(data).hide().fadeIn(this.removeOtherThing));
};
ListView.prototype.removeOtherThing = function(data) {
this.$el.find('other-selector').remove();
};
var listView = new ListView('selector');