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

feat(ivy): add canonical example of a pipe. #21834

Closed
wants to merge 1 commit into from

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Jan 27, 2018

No description provided.

@mhevery mhevery added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Jan 27, 2018
* @param v1 1st argument to {@link PipeTransform#transform}.
*/
export function pipeBind1(index: number, v1: any): any {
throw new Error('TODO: implement!');

Choose a reason for hiding this comment

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

Those functions will be very similar to the existing b0...bV (logic to compare arguments, memorize those etc.). I wanted to refactor those methods so split them up into arguments checking / memorization before - maybe this is a good occasion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we should do this. Also chuck makes a good point that most of the code gen is in form of "{{exp}}"' which translates to b1('', exp, ''). So we should probably have it generate b1(exp)and than have separate instruction to add wrap like sow('', b1(exp),'')` and only generate the wrap if needed.

@pkozlowski-opensource
Copy link
Member

One things I'm missing here is an example showing lifecycle hook(s) on pipes - if I'm not mistaken we can at least have OnDestroy.

Other than this LGTM as a general idea.
We will see more details when the runtime part gets implemented.

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

Not sure if this is WIP and you are also planning to add:

  • runtime impl
  • lifecycle hooks
    in this or a separate PR.

As a very minimum this PR needs re-format - lint is failing

@mhevery
Copy link
Contributor Author

mhevery commented Jan 29, 2018

I was not planning on doing any implementation since this PR was to unblock @chuckjaz on complier implementation. Perhaps you or someone from Amadeus can take on the implementation?

I will fix:

  • fix formating
  • Add Lifecycle hooks.

@mhevery
Copy link
Contributor Author

mhevery commented Jan 29, 2018

@pkozlowski-opensource please have another look.

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

Mostly typos

* Name of the pipe.
*
* The pipe name is used in template bindings. For example if a pipe is named
* `myPipe` than it would be used in the template binding expression like
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: than -> then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

/**
* If Pipe is pure (its output depends only on its input.)
*
* Normally pipe's `translate` method is invoked on each changed detection
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: changed -> change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

*
* Normally pipe's `translate` method is invoked on each changed detection
* cycle. If the cost of invoking the `translated` method is non-trivial and
* if the output of the pipe depends only on its input, than declaring a pipe
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: than -> then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

pure?: boolean;
}

/**
* Pipe decorator and metadata.
*
* Use the `@Pipe` annotation to declare the a given class is a pipe. A pipe
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: declare the a -> declare that a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

* ```
* class MyPipe implements PipeTransform {
* // Generated by Angular Template Compiler
* static ngPipDef = definePipe({
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: ngPipDef -> ngPipeDef

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

n: () => PipeTransform;

/**
* Wether or not the pipe is pure.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: Wether -> Whether

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// NORMATIVE
static ngPipeDef = r3.definePipe({
type: MyPurePipe,
factory: function MyPipe_Factory() { return new MyPipe(); },
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be

factory: function MyPurePipe_Factory() { return new MyPurePipe(); }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

*
* @param index Pipe index where the pipe was stored on creation.
* @param v1 1st argument to {@link PipeTransform#transform}.
* @param v2 1st argument to {@link PipeTransform#transform}.
Copy link
Contributor

@kara kara Jan 30, 2018

Choose a reason for hiding this comment

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

I think all of these in this file say "1st argument". This one should be 2nd, no? Same with others below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

// NORMATIVE
static ngPipeDef = r3.definePipe({
type: MyPurePipe,
factory: function MyPurePipe_Factory() { return new MyPipe(); },
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be new MyPurePipe();, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@ngbot
Copy link

ngbot bot commented Jan 31, 2018

Hi @mhevery! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@mhevery mhevery added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 31, 2018
@alxhub alxhub closed this in 743d8bc Feb 2, 2018
@mhevery mhevery deleted the ivy_pipes branch February 14, 2018 23:01
jbogarthyde pushed a commit to jbogarthyde/angular that referenced this pull request Feb 23, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
@angular-automatic-lock-bot
Copy link

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 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants