Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17,022 changes: 7 additions & 17,015 deletions dist/dataloader.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/actions/DataActionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var DataActionGenerator = function(resourceName) {
'resetView',
'reload',
'populate',
'onPopulateSuccess',
'destroyAll',
'setObject',
'setCollection'
Expand Down
7 changes: 5 additions & 2 deletions lib/components/FilteredDatasource.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ var FilteredDatasource = React.createClass({
var {dataSource} = state;
var {onData} = this.props;
var data = dataSource.getCollection(props.tag);
var {loading, firstLoadComplete} = _.clone(dataSource.getLoadingStatus());

onData && onData(data, dataSource.listenables);
// this clone bug was absolutely insane. let's put this on our dev guide
this.setState({ data: _.clone(data) });
this.setState({ data: _.clone(data), loading, firstLoadComplete });
},

_repopulate(props, state) {
Expand Down Expand Up @@ -170,7 +171,9 @@ var FilteredDatasource = React.createClass({

if (this.state.dataSource && (viewChanged || idChanged) ) {
this.state.dataSource.listenables.resetView(nextProps.tag, false);
this._registerView(nextProps, this.state);
this.setState({loading: true}, () =>{
this._registerView(nextProps, this.state);
})
}

// Checks for parent changes
Expand Down
17 changes: 12 additions & 5 deletions lib/mixins/DataMixin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

var React = require('react');
var _ = require('underscore');
var DSManager = require('../services/DataStoreManager');
Expand All @@ -8,21 +6,30 @@ module.exports = {

getInitialState() {
return {
data:[],
dataSource: null
data: null,
dataSource: null,
firstLoadComplete: false,
loading: true,
};
},

_buildDataProps() {
var props = this._buildProps();
// Nil hack basically.
var {dataSource, loading, firstLoadComplete} = this.state;
var data = this.state.data || (this.props.objectId && {}) || [];

var actions = {};
if (this.state.dataSource) {
actions = this.state.dataSource && this.state.dataSource.listenables;
}
return _.extend(props, {data, actions});
return _.extend(props, {
data,
actions,
dataSource,
firstLoadComplete,
loading,
});
},

_prepareDatasource(config) {
Expand Down
3 changes: 3 additions & 0 deletions lib/services/nsynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ var Nsynchronizer = {
if (objects.constructor === Array) {
formatted = objects.map(this.deserializer.bind(null, object));
this.store.listenables.setCollection(formatted);
setTimeout(() => {
this.store.listenables.onPopulateSuccess();
}, 1000);
}

else {
Expand Down
31 changes: 27 additions & 4 deletions lib/stores/LokiStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function generateStore(options) {
name: name,
collection: collection,
dynamicViews: {},
firstLoadComplete: false,
loading: true,

/**
* Initializes store
Expand All @@ -80,6 +82,23 @@ function generateStore(options) {
this.collection.flushChanges();
},

populate() {
this.loading = true;
this.trigger('loading', this.loading);
},

onPopulateSuccess() {
this.loading = false;
this.firstLoadComplete = true;
this.trigger('loading', this.loading);
},

getLoadingStatus() {
return {
loading: this.loading,
firstLoadComplete: this.firstLoadComplete,
};
},
/**
* Adds an object to the store
* @param {object} object Object to add
Expand Down Expand Up @@ -144,7 +163,11 @@ function generateStore(options) {
* @return {event} Triggers event
*/
destroy(id, trigger=true) {
this.collection.remove(this.get(id));
var objectId = id;
if (typeof id === 'object') {
objectId = id[idAttr];
}
this.collection.remove(this.get(objectId));
this.trigger("destroy", id, trigger);
},

Expand Down Expand Up @@ -215,7 +238,7 @@ function generateStore(options) {
/**
* Queries store
* @param {object} query mongo-style query
* @return {array} Array of reuslts
* @return {array} Array of results
*/
find(query) {
return this.collection.find(query);
Expand All @@ -227,10 +250,10 @@ function generateStore(options) {
* @return {array} Collection of objects
*/
getCollection(tag) {
var collection = [];
var collection = null;
if (tag) {
var view = this.collection.getDynamicView(tag);
collection = view ? view.data() : [];
collection = view ? view.data() : null;
} else {
collection = this.find();
}
Expand Down
Loading