New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(example): adds example for zippy component #729
Conversation
|
It still misses a configurable zippy title though. Not sure how to accomplish that with Angular 2 yet. Any hint on how I can access a components attributes? Or do I need to introduce a local variable for that since Angular 2 only binds against element properties? |
|
Pascal try this might help https://egghead.io/lessons/angularjs-components-and-containers |
|
@ilijamilcinoski this is the Angular 2 repository. The video you're linking there shows directives in Angular 1. |
|
if I understand, access to attributes did not shipped yet, probably... |
| } | ||
| } | ||
|
|
||
| @Component({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think zippy should be in a separate file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
| @Template({ | ||
| url: 'zippy.html' | ||
| }) | ||
| export class Zippy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the component reusable it should fire open and close events. See EventEmmitter example here:
| constructor(@EventEmitter('click') clicker:Function) { |
That way users could do this:
<zippy [title]="..." (open)="..." (close)="...">
|
Could we add some end to end tests to this? (see: https://github.com/angular/angular/blob/master/modules/examples/e2e_test/hello_world/hello_world_spec.es6) |
| selector: 'zippy-app' | ||
| }) | ||
| @Template({ | ||
| inline: `<zippy title="Details"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhevery To not confuse others, do you think it make sense to change title="" to [title]="" in order to make explicitly clear that we're binding to a property? And while we're at it: omitting [] here is okay because every element has a title property by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand. With your current implementation the template author using Zippy can write:
<zippy title="Greeting"> String literal
<zippy [title]=" 'Greet' + 'ing' "> As expression.
This is the choice of the template author and not of the component author. (This is a big change from NG1 which may not be obvious at first.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. Got it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And even
<zippy title="{{ 'Greet' + 'ing' }}"> As expression.
|
Gonna try to make tests work and update this PR accordingly. EventEmitting is implemented but not pushed yet. |
| This is some content. | ||
| </zippy> | ||
| <ul> | ||
| <li *foreach="var log in logs">{{log.msg}}<li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhevery This basically works, however, for some reason there's initially already a <li> element even if this.logs === []. Not sure if this is the intended behaviour in Angular 2. Might also be because we don't use template syntax anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely not intended, could you please try to add a test in foreach_spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarifying! Yes, I'll try to add a test :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is something wrong with the test and you want to investigate a little bit more, you should probably check what happens in Foreach.ietrableChanges()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the hint!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vicb turns out there's a little tiny typo in my code that causes the bug as stated here #809 (comment) :)
|
Hey folks, just wanted to leave some feedback so not that you think I disappeared. I'm currently busy due to ng-conf and other stuff, I'm going to continue working on this PR after ng-conf. Hope to meet some of you there :) |
|
Okay, with the help of @vicb I'm a bit further! Build is almost running, now getting these errors: Investigating now |
|
IIRC @btford had this error, let me try to find something for you |
|
Doesn't seem to be an exact duplicate but it might help ? |
|
Renaming |
what about serving dev ? |
|
Works for the hello world example though. Taking a closer look now |
|
May be you should push an updated version ? |
|
@vicb updated the PR and pushed the latest |
| class ZippyApp { | ||
| logs: List<string>; | ||
|
|
||
| constructor() { this.logs = []; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move init to decl
|
@vicb changes pushed. Converting the tests now. |
|
|
||
| it('should toggle when the zippy title is clicked', function() { | ||
| element(by.css('.zippy__title')).click(); | ||
| expect(element(by.css('.zippy__content')).isDisplayed()).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toEqual ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, will change this. Any thoughts on when to use toBe() then? I used to use toEqual() for strings and toBe() for boolean values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toBe() compares references (ie two arrays/objects could satisfy .toEqual() but not .toBe()).
I have a slight preference for .toEqual() here because that's really what you want to assert. However .toBe() should work equally fine if it was working (Travis logs seem to indicate that it is not part of the decl files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great insights, thanks man!
|
Updated PR accordingly |
| toggle() { | ||
| this.visible = !this.visible; | ||
| if (this.visible) { | ||
| this.openHandler.next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObservableWrapper.callNext()...
Almost there !
|
You probably want to update |
| toggle() { | ||
| this.visible = !this.visible; | ||
| if (this.visible) { | ||
| ObservableWrapper.callNext(this.openHandler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing ";" & below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 args or Dart will yell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second argument would be an empty object then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever your handler should receive... null ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't receive anything. Okay, I go with null then. :)
|
Argh. forgot that one. Updated! |
|
Travis is happy |
|
@vicb thank you so much for your help! I hope future contributions won't be so hairy. I'm now a bit more experienced with the Angular 2 code base :) |
|
landed as 783654e Looking forward to your next contributions. |
|
|
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |




This commit adds a very simple zippy component implementation to the
examplescollection.Closes #696
ACTION:
open/closeevent