Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #38 : Emptiness detection is not correctly resolved for children with several promises #39

Merged
merged 3 commits into from
Jun 12, 2016
Merged
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ Performs a single request to retrieve the resources required by the whole compon
### setup

After the resources are loaded, stores a `$view` reference, sets up some resources, caches the tags defined in `this.S`, automatically calls `bindEvents` and performs children set up.
Implicit flow during `setup`:
* `this.$view` is set
* `translateOptions` is called
* `configureComponent` is called (you should overwrite it and call `appendToView` to initialize view)
* `_findLocalElems` is called (sets `this.t` with cached tags)
* `bindEvents` is called (you should overwrite it for event binding)
* `childrenSetup` is called
* `READY` event is triggered
* `setupCompleted` is called

### setData

If the component includes capabilities to communicate with the server using a proxy (i.e. by composition of FetchHandler) they can retrieve data and load it into the components tree.
If the component includes capabilities to communicate with the server using a proxy (i.e. they extend from BaseWithProxy) they can retrieve a payload to load data into the component tree.

## component's api I (data flow)

Expand Down
12 changes: 11 additions & 1 deletion src/blocks/base-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,17 @@ define([
// Resolved promise callback considers emptiness check result (emptyState)
var allChildrenEmptiness = Promise.all(childrenEmptinessPromisesArray),
chainAllChildrenEmptiness = allChildrenEmptiness.then(function(results) {
var isLocalEmpty = self.checkLocalEmptiness(results[0]);
// Check all results are true
var isLocalEmpty = results.every(function(value) {
if (typeof value === 'boolean') {
return value === true;
} else if (typeof value === 'object') {
return self.checkLocalEmptiness(value);
} else {
Logger.error('base-ui : unknown child emptiness result', value);
return false;
}
});
// Empty if promise results are empty and outter result is empty too
return emptyState && isLocalEmpty;
});
Expand Down
10 changes: 6 additions & 4 deletions src/data-flow/save/binder.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ define([
*/
_performSaveErrorActions : function(uiErrorCallback, errors) {
Logger.warn('SaveBehavior: unable to save data', arguments);
// NOTICE:
// testing if `errors` is an array is a hint to know if it is a set of validation errors
if ('function' === typeof uiErrorCallback && $.isArray(errors)) {
uiErrorCallback(errors);

if ('function' === typeof uiErrorCallback) {
var wasHandledByUi = uiErrorCallback(errors);
if (!wasHandledByUi) {
this.opts.onComponentSaveError(errors);
}
} else {
this.opts.onComponentSaveError(errors);
}
Expand Down