-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11231 from rwjblue/fix-legacy-each-else-block
[BUGFIX beta] Fix {{each}} with `itemViewClass` and {{else}}.
- Loading branch information
Showing
5 changed files
with
87 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{~#each view._arrangedContent as |item|}}{{#if attrs.itemViewClass}}{{#view attrs.itemViewClass controller=item _defaultTagName=view._itemTagName}}{{legacy-yield item}}{{/view}}{{else}}{{legacy-yield item controller=item}}{{/if}}{{else if attrs.emptyViewClass}}{{view attrs.emptyViewClass _defaultTagName=view._itemTagName}}{{/each~}} | ||
{{~#each view._arrangedContent as |item|}}{{#if attrs.itemViewClass}}{{#view attrs.itemViewClass controller=item _defaultTagName=view._itemTagName}}{{legacy-yield item}}{{/view}}{{else}}{{legacy-yield item controller=item}}{{/if}}{{else if view._emptyView}}{{view view._emptyView _defaultTagName=view._itemTagName}}{{/each~}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
@module ember | ||
@submodule ember-views | ||
*/ | ||
|
||
import { Mixin } from "ember-metal/mixin"; | ||
import View from "ember-views/views/view"; | ||
import { get } from "ember-metal/property_get"; | ||
import { set } from "ember-metal/property_set"; | ||
import { computed } from "ember-metal/computed"; | ||
|
||
/** | ||
@class EmptyViewSupport | ||
@namespace Ember | ||
*/ | ||
export default Mixin.create({ | ||
/** | ||
This provides metadata about what kind of empty view class this | ||
collection would like if it is being instantiated from another | ||
system (like Handlebars) | ||
@private | ||
@property emptyViewClass | ||
*/ | ||
emptyViewClass: View, | ||
|
||
/** | ||
An optional view to display if content is set to an empty array. | ||
@property emptyView | ||
@type Ember.View | ||
@default null | ||
*/ | ||
emptyView: null, | ||
|
||
_emptyView: computed('emptyView', 'attrs.emptyViewClass', 'emptyViewClass', function() { | ||
var emptyView = get(this, 'emptyView'); | ||
var attrsEmptyViewClass = this.getAttr('emptyViewClass'); | ||
var emptyViewClass = get(this, 'emptyViewClass'); | ||
var inverse = get(this, '_itemViewInverse'); | ||
var actualEmpty = emptyView || attrsEmptyViewClass; | ||
|
||
// Somehow, our previous semantics differed depending on whether the | ||
// `emptyViewClass` was provided on the JavaScript class or via the | ||
// Handlebars template. | ||
// In Glimmer, we disambiguate between the two by checking first (and | ||
// preferring) the attrs-supplied class. | ||
// If not present, we fall back to the class's `emptyViewClass`, but only | ||
// if an inverse has been provided via an `{{else}}`. | ||
if (inverse && actualEmpty) { | ||
if (actualEmpty.extend) { | ||
return actualEmpty.extend({ template: inverse }); | ||
} else { | ||
set(actualEmpty, 'template', inverse); | ||
} | ||
} else if (inverse && emptyViewClass) { | ||
return emptyViewClass.extend({ template: inverse }); | ||
} | ||
|
||
return actualEmpty; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters