Skip to content

Instantly share code, notes, and snippets.

@patocallaghan
Last active August 14, 2018 05:22
Show Gist options
  • Save patocallaghan/b4e2bc4f0e00575d54ebd3bf1877f3ea to your computer and use it in GitHub Desktop.
Save patocallaghan/b4e2bc4f0e00575d54ebd3bf1877f3ea to your computer and use it in GitHub Desktop.
Helper Reproduction
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
type: 'all',
init() {
this.set('comment', this.comment1);
},
comment1: {
parentComment: {
isOpen: false,
},
isReply: true
},
comment2: {
parentComment: {
isOpen: true,
},
isReply: false
},
});
import { helper as buildHelper } from '@ember/component/helper';
export default buildHelper(function(params) {
let comment = params[0],
type = params[1],
retValue = false;
switch (type) {
case 'all':
if(comment[0] !== undefined) {
retValue = false;
} else {
retValue = true;
}
break;
case 'unresolved':
if(comment[0] !== undefined) {
if((comment.filterBy('isOpen', true)).length > 0) {
retValue = false;
} retValue = true;
} else if (comment.isReply && comment.parentComment.isOpen) {
retValue = true;
} else if (!(comment.isReply) && comment.isOpen) {
retValue = true;
}
break;
case 'resolved':
if(comment[0] !== undefined) {
if((comment.filterBy('isOpen', false)).length > 0) {
retValue = false;
}
retValue = true;
} else if (comment.isReply && comment.parentComment.isOpen !== true) {
retValue = true;
} else if (!(comment.isReply) && comment.isOpen !== true) {
retValue = true;
}
break;
}
return retValue;
});
<p>
{{#if (comt-helper comment type)}}
All<br>
comment.parentComment.isOpen: {{comment.parentComment.isOpen}}
{{else}}
Unresolved<br>
comment.parentComment.isOpen: {{comment.parentComment.isOpen}}
{{/if}}
</p>
<button {{action (mut type) 'unresolved'}}>Change to "Unresolved"</button>
<button {{action (mut type) 'all'}}>Change to "All"</button>
<br>
<button {{action (mut comment) comment1}}>Change to "comment1"</button>
<button {{action (mut comment) comment2}}>Change to "comment2"</button>
{
"version": "0.15.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.0.0",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment