Skip to content

Commit

Permalink
Improve computed property logic. #133
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer committed Sep 2, 2015
1 parent b6c2f3d commit 058b072
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
22 changes: 12 additions & 10 deletions src/app/components/StreamItemComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ define([
showFlag: bool( "settings.gui_flagsvisible" ),

faded: function() {
var filter = get( this, "settings.gui_filterstreams" );
var filters = get( this, "settings.gui_langfilter" );
var clang = get( this, "channel.language" );
var blang = get( this, "channel.broadcaster_language" );

return !filter
// a channel language needs to be set
&& clang
if ( get( this, "settings.gui_filterstreams" ) ) {
return false;
}

var filter = get( this, "settings.gui_langfilter" );
var clang = get( this, "channel.language" );
var blang = get( this, "channel.broadcaster_language" );

// a channel language needs to be set
return clang
&& (
// fade out if
// no broadcaster language is set and channel language is filtered out
!blang && filters[ clang ] === false
!blang && filter[ clang ] === false
// OR broadcaster language is set and filtered out (ignore channel language)
|| blang && filters[ blang ] === false
|| blang && filter[ blang ] === false
);
}.property(
"settings.gui_langfilter",
Expand Down
22 changes: 11 additions & 11 deletions src/app/mixins/LanguageFilterMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ define( [ "Ember" ], function( Ember ) {
* @returns {(string[]|undefined)}
*/
broadcaster_language: function() {
if ( get( this, "settings.gui_filterstreams" ) ) {
var filters = get( this, "settings.gui_langfilter" );
if ( !filters ) { return; }
if ( !get( this, "settings.gui_filterstreams" ) ) { return; }

var keys = Object.keys( filters );
var filtered = keys.filter(function( lang ) {
return filters[ lang ];
}, filters );
var filters = get( this, "settings.gui_langfilter" );
if ( !filters ) { return; }

// ignore everything (un)checked
if ( filtered.length > 0 && filtered.length !== keys.length ) {
return filtered;
}
var keys = Object.keys( filters );
var filtered = keys.filter(function( lang ) {
return filters[ lang ];
}, filters );

// ignore everything (un)checked
if ( filtered.length > 0 && filtered.length !== keys.length ) {
return filtered;
}
}.property( "settings.gui_filterstreams", "settings.gui_langfilter" )
});
Expand Down

0 comments on commit 058b072

Please sign in to comment.