★ wanayoo — archive 1999 https://github.com/angular/angular/pull/729Nouvelle recherche | Portail wanayoo
Skip to content
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

Closed
wants to merge 1 commit into from
Closed

chore(example): adds example for zippy component #729

wants to merge 1 commit into from

Conversation

0x-r4bbit
Copy link
Contributor

@0x-r4bbit 0x-r4bbit commented Feb 20, 2015

This commit adds a very simple zippy component implementation to the
examples collection.

Closes #696

ACTION:

  • add open/close event
  • add tests

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Feb 20, 2015

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?

@ilijamilcinoski
Copy link

ilijamilcinoski commented Feb 20, 2015

Pascal try this might help https://egghead.io/lessons/angularjs-components-and-containers

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Feb 20, 2015

@ilijamilcinoski this is the Angular 2 repository. The video you're linking there shows directives in Angular 1.

@otodockal
Copy link
Contributor

otodockal commented Feb 20, 2015

if I understand, access to attributes did not shipped yet, probably...

}
}

@Component({
Copy link
Contributor

@mhevery mhevery Feb 20, 2015

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.

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Feb 20, 2015

@mhevery Updated the PR, thank you commenting and helping me out making this a nice small component :)

@vicb Thank you for explaining the reflection thing. I think I need to read up on that since I'm not into Dart. :)

@Template({
url: 'zippy.html'
})
export class Zippy {
Copy link
Contributor

@mhevery mhevery Feb 20, 2015

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)="...">

@mhevery
Copy link
Contributor

mhevery commented Feb 20, 2015

selector: 'zippy-app'
})
@Template({
inline: `<zippy title="Details">
Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 20, 2015

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?

Copy link
Contributor

@mhevery mhevery Feb 20, 2015

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.)

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Got it.

Copy link
Contributor

@mhevery mhevery Feb 21, 2015

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.

@mhevery mhevery added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Feb 21, 2015
@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Feb 21, 2015

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>
Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 24, 2015

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?

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2015-02-24 at 10 06 48

Copy link
Contributor

@vicb vicb Feb 24, 2015

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

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 24, 2015

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 :)

Copy link
Contributor

@vicb vicb Feb 24, 2015

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()

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Feb 24, 2015

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!

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Mar 15, 2015

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) :)

@mhevery mhevery modified the milestone: M5: Early Adopters Feb 24, 2015
@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Feb 26, 2015

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 :)

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 17, 2015

Okay, with the help of @vicb I'm a bit further! Build is almost running, now getting these errors:

$ gulp build
Dart SDK detected
[13:49:15] Using gulpfile ~/projects/angular/angular/gulpfile.js
[13:49:15] Starting 'build/clean.js'...
[13:49:15] Starting 'build/clean.tools'...
[13:49:15] Finished 'build/clean.tools' after 1.29 ms
[13:49:15] Starting 'build.tools'...
[13:49:15] Starting '!build.tools'...
[13:49:15] Starting 'build.dart'...
[13:49:15] Starting 'build/packages.dart'...
[13:49:15] Starting 'build/clean.dart'...
[13:49:15] Starting 'build/clean.tools'...
[13:49:15] Finished 'build/clean.tools' after 88 μs
[13:49:15] Finished 'build/clean.js' after 130 ms
[13:49:15] Starting 'build.js.dev'...
[13:49:15] Starting 'build/clean.tools'...
[13:49:15] Finished 'build/clean.tools' after 99 μs
[13:49:15] Finished 'build/clean.dart' after 6.06 ms
[13:49:19] Finished '!build.tools' after 4.15 s
[13:49:19] Finished 'build.tools' after 4.15 s
[13:49:19] Starting 'broccoli.js.dev'...
[13:49:19] Starting '!broccoli.js.dev'...
[13:49:19] Starting 'build/tree.dart'...
[13:49:19] Starting '!build/tree.dart'...
[13:49:19] Starting 'build.js.prod'...
[13:49:19] Starting 'build.js.cjs'...
[13:49:19] Starting '!build.js.cjs'...

Slowest Trees                                 | Total
----------------------------------------------+---------------------
Funnel                                        | 40412ms
DiffingTSCompiler                             | 10801ms

Slowest Trees (cumulative)                    | Total (avg)
----------------------------------------------+---------------------
Funnel (7)                                    | 40714ms (5816 ms)
DiffingTSCompiler (1)                         | 10801ms

creating node_modules symlink hack
creating link dist/js/cjs/node_modules/angular2 ../angular2
creating link dist/js/cjs/node_modules/benchmarks ../benchmarks
creating link dist/js/cjs/node_modules/benchmarks_external ../benchmarks_external
creating link dist/js/cjs/node_modules/benchpress ../benchpress
creating link dist/js/cjs/node_modules/examples ../examples
creating link dist/js/cjs/node_modules/rtts_assert ../rtts_assert
[13:50:14] Finished '!build.js.cjs' after 54 s
[13:50:14] Finished 'build.js.cjs' after 54 s
[13:50:38] '!broccoli.js.dev' errored after 1.32 min
[13:50:38] Error: [MergeTrees]: Duplicate path found while merging trees. Path: "examples/src/zippy_component/index.js".
Either remove the duplicate or enable the "overwrite" option for this merge.
    at pathOverwrittenError (/Users/pp/projects/angular/angular/broccoli-merge-trees.ts:21:10)
    at /Users/pp/projects/angular/angular/broccoli-merge-trees.ts:67:19
    at Array.forEach (native)
    at /Users/pp/projects/angular/angular/broccoli-merge-trees.ts:58:29
    at Array.forEach (native)
    at MergeTrees.rebuild (/Users/pp/projects/angular/angular/broccoli-merge-trees.ts:56:27)
    at DiffingPluginWrapper.rebuild (/Users/pp/projects/angular/angular/diffing-broccoli-plugin.ts:86:47)
    at /Users/pp/projects/angular/angular/node_modules/broccoli/lib/api_compat.js:42:21
    at lib$rsvp$$internal$$tryCatch (/Users/pp/projects/angular/angular/node_modules/broccoli/node_modules/rsvp/dist/rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (/Users/pp/projects/angular/angular/node_modules/broccoli/node_modules/rsvp/dist/rsvp.js:501:17)
[13:50:38] 'build.dart' errored after 1.38 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/packages.dart' errored after 1.38 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build.js.dev' errored after 1.38 min
[13:50:38] Error: build sequence failed
[13:50:38] 'broccoli.js.dev' errored after 1.32 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/tree.dart' errored after 1.3 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/tree.dart' errored after 1.3 min
[13:50:38] Error: build sequence failed
[13:50:38] 'broccoli.js.dev' errored after 1.32 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/tree.dart' errored after 1.3 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build.js.dev' errored after 1.38 min
[13:50:38] Error: build sequence failed
[13:50:38] 'broccoli.js.dev' errored after 1.32 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/tree.dart' errored after 1.3 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/packages.dart' errored after 1.38 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build.js.dev' errored after 1.38 min
[13:50:38] Error: build sequence failed
[13:50:38] 'broccoli.js.dev' errored after 1.32 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build/tree.dart' errored after 1.3 min
[13:50:38] Error: build sequence failed
[13:50:38] 'build.js.prod' errored after 1.3 min
[13:50:38] Error: [MergeTrees]: Duplicate path found while merging trees. Path: "examples/src/zippy_component/index.js".
Either remove the duplicate or enable the "overwrite" option for this merge.
    at pathOverwrittenError (/Users/pp/projects/angular/angular/broccoli-merge-trees.ts:21:10)
    at /Users/pp/projects/angular/angular/broccoli-merge-trees.ts:67:19
    at Array.forEach (native)
    at /Users/pp/projects/angular/angular/broccoli-merge-trees.ts:58:29
    at Array.forEach (native)
    at MergeTrees.rebuild (/Users/pp/projects/angular/angular/broccoli-merge-trees.ts:56:27)
    at DiffingPluginWrapper.rebuild (/Users/pp/projects/angular/angular/diffing-broccoli-plugin.ts:86:47)
    at /Users/pp/projects/angular/angular/node_modules/broccoli/lib/api_compat.js:42:21
    at lib$rsvp$$internal$$tryCatch (/Users/pp/projects/angular/angular/node_modules/broccoli/node_modules/rsvp/dist/rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (/Users/pp/projects/angular/angular/node_modules/broccoli/node_modules/rsvp/dist/rsvp.js:501:17)

Slowest Trees                                 | Total
----------------------------------------------+---------------------
DartFormatter                                 | 32087ms
Funnel                                        | 28287ms
Funnel                                        | 11907ms
TSToDartTranspiler                            | 6300ms

Slowest Trees (cumulative)                    | Total (avg)
----------------------------------------------+---------------------
Funnel (10)                                   | 40944ms (4094 ms)
DartFormatter (1)                             | 32087ms
TSToDartTranspiler (1)                        | 6300ms

[13:50:42] Finished '!build/tree.dart' after 1.37 min
[13:50:42] Starting 'cleanup.builder'...

Investigating now

@vicb
Copy link
Contributor

vicb commented Jun 17, 2015

IIRC @btford had this error, let me try to find something for you

@vicb
Copy link
Contributor

vicb commented Jun 17, 2015

Doesn't seem to be an exact duplicate but it might help ?

We suspect a race condition that’s only present on my machine.
(workaround was to comment out that exception)
FWIW, the offending files are facade sourcemaps
async.js.map and friends

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 17, 2015

Renaming js files to ts files helped. The dart.analyzer task is failing massively but I'm going with gulp.js.dev for now..

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 17, 2015

Anything I need to change in the build process to get around those issues?

This is what I get after running gulp build.js.cjs and gulp serve.js.prod

screen shot 2015-06-17 at 14 43 38

@vicb
Copy link
Contributor

vicb commented Jun 17, 2015

This is what I get after running gulp build.js.cjs and gulp serve.js.prod

what about serving dev ?

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 20, 2015

Unfortunately, this gives me exactly the same =/

screen shot 2015-06-20 at 13 07 19

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 20, 2015

Works for the hello world example though. Taking a closer look now

@vicb
Copy link
Contributor

vicb commented Jun 20, 2015

May be you should push an updated version ?

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

@vicb updated the PR and pushed the latest

class ZippyApp {
logs: List<string>;

constructor() { this.logs = []; }
Copy link
Contributor

@vicb vicb Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move init to decl

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

@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);
Copy link
Contributor

@vicb vicb Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toEqual ?

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Jun 22, 2015

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

Copy link
Contributor

@vicb vicb Jun 22, 2015

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).

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great insights, thanks man!

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

Updated PR accordingly

toggle() {
this.visible = !this.visible;
if (this.visible) {
this.openHandler.next();
Copy link
Contributor

@vicb vicb Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObservableWrapper.callNext()...

Almost there !

@vicb
Copy link
Contributor

vicb commented Jun 22, 2015

You probably want to update browser_tree.ts to copy the js scripts to the output folder (the ones reported as 404)

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

Using ObservableWrapper now and updated browser_tree.ts. Running into this issue now:

screen shot 2015-06-22 at 15 35 47

toggle() {
this.visible = !this.visible;
if (this.visible) {
ObservableWrapper.callNext(this.openHandler)
Copy link
Contributor

@vicb vicb Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ";" & below

Copy link
Contributor

@vicb vicb Jun 22, 2015

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

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Jun 22, 2015

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?

Copy link
Contributor

@vicb vicb Jun 22, 2015

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 ?

Copy link
Contributor Author

@0x-r4bbit 0x-r4bbit Jun 22, 2015

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. :)

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

Argh. forgot that one. Updated!

@vicb
Copy link
Contributor

vicb commented Jun 22, 2015

Travis is happy 🎉
I'll wait for the last run before merging. Thanks for your work on this PR!

@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

@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 :)

@vicb
Copy link
Contributor

vicb commented Jun 22, 2015

landed as 783654e

Looking forward to your next contributions.

@vicb vicb closed this Jun 22, 2015
@0x-r4bbit
Copy link
Contributor Author

0x-r4bbit commented Jun 22, 2015

🎉 Yaaay! 🎉

@angular-automatic-lock-bot
Copy link

angular-automatic-lock-bot bot commented Sep 6, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add zippy example