Skip to content

Instantly share code, notes, and snippets.

@javlc
Forked from jhoye/components.input-output.js
Last active April 19, 2017 14:20
Show Gist options
  • Save javlc/36f7d7e8fc03ece93d90850bcdedfa25 to your computer and use it in GitHub Desktop.
Save javlc/36f7d7e8fc03ece93d90850bcdedfa25 to your computer and use it in GitHub Desktop.
Component Interaction
import Ember from 'ember';
export default Ember.Component.extend({
input: '',
output: '',
actions: {
send() {
//console.log('sendHandler: ' + this.get('sendHandler'));
//this.sendAction(this.get('sendHandler'), this.get('input'));
this.sendAction('sendHandler', this.get('input'));
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Component Interaction'
});
import Ember from 'ember';
var Output = Ember.Object.extend({output1: '', output2: ''});
export default Ember.Route.extend({
output: Output.create(),
model() {
return this.get('output');
},
actions: {
receiveComponent1(text, componentModel) {
this.controller.model.set('output2', text);
// or:
//this.modelFor('index').set('output2', text);
// or:
//this.get('output').set('output2', text);
},
receiveComponent2(text, componentModel) {
this.controller.model.set('output1', text);
}
}
});
<h1>{{appName}}</h1>
{{outlet}}
<hr/>
{{yield}}
<div>{{input value=input key-up="send"}}</div>
<div>{{output}}&nbsp;</div>
{{log output}}
<h2>Index</h2>
{{#my-component
output=model.output1
sendHandler="receiveComponent1"}}
<h3>Component 1</h3>
{{/my-component}}
{{#my-component
output=model.output2
sendHandler="receiveComponent2"}}
<h3>Component 2</h3>
{{/my-component}}
{{outlet}}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.10.2",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment