Created
February 24, 2016 16:52
-
-
Save runspired/e78b0c40acc462292abb to your computer and use it in GitHub Desktop.
Example Named Yields Result, this is would be the result of AST walker transformation, but can be wired manually.
This file contains hidden or 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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
header: { title: 'HEADER' }, | |
footer: { title: 'FOOTER' }, | |
body: { title: 'BODY' }, | |
slots: null, | |
_registerSlot(name) { | |
this.slots.set(name, true); | |
}, | |
init() { | |
this._super(); | |
this.slots = this.slots || Ember.Object.create({}); | |
} | |
}); |
This file contains hidden or 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
import Ember from 'ember'; | |
const { | |
assert, | |
Component, | |
computed | |
} = Ember; | |
const component = Component.extend({ | |
tagName: '', | |
name: '', | |
// TODO error if slot length is greater than 6 | |
slot: null, | |
register: null, | |
shouldDisplay: computed('name', 'slot.name', function() { | |
return this.get('name') === this.get('slot.name'); | |
}), | |
p1: computed('slot.params.[]', function() { | |
return this.get('slot.params').objectAt(0); | |
}), | |
p2: computed('slot.params.[]', function() { | |
return this.get('slot.params').objectAt(1); | |
}), | |
p3: computed('slot.params.[]', function() { | |
return this.get('slot.params').objectAt(2); | |
}), | |
p4: computed('slot.params.[]', function() { | |
return this.get('slot.params').objectAt(3); | |
}), | |
p5: computed('slot.params.[]', function() { | |
return this.get('slot.params').objectAt(4); | |
}), | |
init() { | |
this._super(); | |
assert("You must include a name for your block", this.name); | |
this.slot.register(this.name); | |
} | |
}); | |
component.reopenClass({ | |
positionalParams: ['slot', 'name'] | |
}); | |
export default component; |
This file contains hidden or 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
import Ember from 'ember'; | |
export function arr(params/*, hash*/) { | |
return Ember.A(params); | |
} | |
export default Ember.Helper.helper(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
faked-yields
is an example component utilizing slotsslot-proxy
is how we make this work, but comes with a perf overhead since all yields are now wrapped with an extra component and layerarr
is just a helper to make it easy to pass a lot of args together as an array (vs as ahash
, may make sense to just passp1
etc. in a hash, would likely reduce overhead, but I have not investigated)example-usage
is how you would compose with a component with slots in a template.What do these look like before AST transforms?