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
Conversation
* @param v1 1st argument to {@link PipeTransform#transform}. | ||
*/ | ||
export function pipeBind1(index: number, v1: any): any { | ||
throw new Error('TODO: implement!'); |
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.
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?
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.
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 so
w('', b1(exp),'')` and only generate the wrap if needed.
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 Other than this LGTM as a general idea. |
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 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
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:
|
@pkozlowski-opensource please have another look. |
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.
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 |
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.
Typo: than -> 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.
👍
/** | ||
* If Pipe is pure (its output depends only on its input.) | ||
* | ||
* Normally pipe's `translate` method is invoked on each changed detection |
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.
Typo: changed -> change
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.
👍
* | ||
* 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 |
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.
Typo: than -> 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.
👍
pure?: boolean; | ||
} | ||
|
||
/** | ||
* Pipe decorator and metadata. | ||
* | ||
* Use the `@Pipe` annotation to declare the a given class is a pipe. A pipe |
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.
Typo: declare the a -> declare that a
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.
👍
* ``` | ||
* class MyPipe implements PipeTransform { | ||
* // Generated by Angular Template Compiler | ||
* static ngPipDef = definePipe({ |
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.
Typo: ngPipDef -> ngPipeDef
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.
👍
n: () => PipeTransform; | ||
|
||
/** | ||
* Wether or not the pipe is pure. |
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.
Typo: Wether -> Whether
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.
👍
// NORMATIVE | ||
static ngPipeDef = r3.definePipe({ | ||
type: MyPurePipe, | ||
factory: function MyPipe_Factory() { return new MyPipe(); }, |
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 this should be
factory: function MyPurePipe_Factory() { return new MyPurePipe(); }
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.
👍
All concerns addressed
packages/core/src/render3/pipe.ts
Outdated
* | ||
* @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}. |
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 all of these in this file say "1st argument". This one should be 2nd, no? Same with others 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.
fixed
// NORMATIVE | ||
static ngPipeDef = r3.definePipe({ | ||
type: MyPurePipe, | ||
factory: function MyPurePipe_Factory() { return new MyPipe(); }, |
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.
Should be new MyPurePipe();
, right?
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.
fixed
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.
LGTM
Hi @mhevery! This PR has merge conflicts due to recent upstream merges. |
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. |
No description provided.