Skip to content

Instantly share code, notes, and snippets.

@ASH-Michael
Last active May 30, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ASH-Michael/ac707268c5b590cbe2184a71e5d6ab76 to your computer and use it in GitHub Desktop.
Save ASH-Michael/ac707268c5b590cbe2184a71e5d6ab76 to your computer and use it in GitHub Desktop.
DDAU with mut
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['first-component component']
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['fourth-component component']
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['second-component component']
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['third-component component']
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
updateName(newName) {
Ember.set(this, 'appName', newName);
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
p {
margin: 0.5rem 0;
}
.component {
padding-top: 0.25rem;
}
.component .component-text {
padding-left: 1rem;
}
.first-component strong,
.first-component span {
color: red;
}
.second-component strong,
.second-component span {
color: purple;
}
.third-component strong,
.third-component span {
color: blue;
}
.fourth-component strong,
.fourth-component span {
color: green;
}
<h1>Welcome to "{{appName}}"</h1>
<p>Following Data Down Actions Up (DDAU), you can either pass an action down from the controller to update a controller value or you can use the mut helper.</p>
<p>Using the <code>mut</code> helper in an action is equivalent to writing an action to set the property with the new value. This will DRY up your code by eliminating the extra steps of creating an action and passing it down with your mutable property.</p>
<p><strong>Enter a new <code>appName</code> value and hit enter.</strong></p>
<br>
{{first-component
appName=appName
updateName=(action 'updateName')
}}
<p><strong>&#123;&#123; first-component</strong></p>
<div class="component-text">
<p><span>appName="{{appName}}"</span></p>
<p>Update <code>appName</code> with action: {{input enter=(action updateName)}}</p>
<p>Update <code>appName</code> with mut: {{input enter=(action (mut appName))}}</p>
{{second-component
appName=appName
updateName=(action updateName)
}}
</div>
<p><strong>&#125;&#125;</strong></p>
<p><strong>&#123;&#123; fourth-component</strong></p>
<div class="component-text">
<p><span>appName="{{appName}}"</span></p>
<p>Update <code>appName</code> with action: {{input enter=(action updateName)}}</p>
<p>Update <code>appName</code> with mut: {{input enter=(action (mut appName))}}</p>
</div>
<p><strong>&#125;&#125;</strong></p>
<p><strong>&#123;&#123; second-component</strong></p>
<div class="component-text">
<p><span>appName="{{appName}}"</span></p>
<p>Update <code>appName</code> with action: {{input enter=(action updateName)}}</p>
<p>Update <code>appName</code> with mut: {{input enter=(action (mut appName))}}</p>
{{third-component
appName=appName
updateName=(action updateName)
}}
</div>
<p><strong>&#125;&#125;</strong></p>
<p><strong>&#123;&#123; third-component</strong></p>
<div class="component-text">
<p><span>appName="{{appName}}"</span></p>
<p>Update <code>appName</code> with action: {{input enter=(action updateName)}}</p>
<p>Update <code>appName</code> with mut: {{input enter=(action (mut appName))}}</p>
{{fourth-component
appName=appName
updateName=(action updateName)
}}
</div>
<p><strong>&#125;&#125;</strong></p>
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment