Title: Add node processing hook to $compile public API. · Issue #15270 · angular/angular.js · GitHub
Open Graph Title: Add node processing hook to $compile public API. · Issue #15270 · angular/angular.js
X Title: Add node processing hook to $compile public API. · Issue #15270 · angular/angular.js
Description: Do you want to request a feature or report a bug? Feature What is the current behavior? I have no way of modifying a node before the majority of compile functionality takes place (that I've found, and yes, I've read the source :) ). Supp...
Open Graph Description: Do you want to request a feature or report a bug? Feature What is the current behavior? I have no way of modifying a node before the majority of compile functionality takes place (that I've found, ...
X Description: Do you want to request a feature or report a bug? Feature What is the current behavior? I have no way of modifying a node before the majority of compile functionality takes place (that I've fou...
Opengraph URL: https://github.com/angular/angular.js/issues/15270
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add node processing hook to $compile public API.","articleBody":"**Do you want to request a _feature_ or report a _bug_?**\n\nFeature\n\n**What is the current behavior?**\n\nI have no way of modifying a node before the majority of compile functionality takes place (that I've found, and yes, I've read the source :) ).\n\nSuppose I want all components named `mySubmenu` to also have the directive `genericStateListener` applied to them. I've separated out a lot of ui-router state based functionality into it's own directive, in keeping with the separation of concerns principle. I don't want a bunch of generic state handling logic clogging up my component controller. Additionally, I may want to use this state logic on other components that are concerned with state transitions.\n\nWell, to do this, I have two options (that I know of):\n\n1) I could place the directive `genericStateListener` in every place I use `mySubmenu`. Well, that's annoying :)\n2) I could wrap my template for `mySubmenu` in a block which has the `genericStateListener` directive. This is workable, but it bothers me that someone else viewing my code needs to go into my template to understand that this component has state listening functionality. Additionally, if I want to interact with the `genericStateListener` directive controller, I cannot require it, because it's BELOW me now.\n\nNow the situation becomes even MORE complex (but also more simple) in the instance that, perhaps I don't want to be tied to a particular functionality/directive for listening to states. I want to abstract it further. In fact, I just want to be able to put an `isStateListener` field on my component. Then, by overriding the `.component` decorator, I can add an annotated field `$stateListener` every time I see this field on my `options` object. GREAT I now have a way to check if the user wants to have stateListener functionality on the component I'm compiling! These are the kinds of things I can EASILY do already in angular's current state. There's only one problem, even once I get said attribute on the final directive object... I can't do anything with it.\n\nThere's no way of modifying a node prior to the start of the compilation process (before directives are collected). By the time I can add functionality to the $compile process, directives have already been collected. This seriously hampers extensibility of the component object.\n\n**What is the expected behavior?**\n\nI would expect there to be a publicly accessible function to be run somewhere in the `collectDirective` function, like this:\n\n```\n switch (nodeType) {\n case NODE_TYPE_ELEMENT: /* Element */\n // use the node name: \u003cdirective>\n runNodeTransforms(nodeName_(node),node); // function exposed on $compileProvider\n addDirective(directives,\n directiveNormalize(nodeName_(node)), 'E', maxPriority, ignoreDirective);\n\n // iterate over the attributes\n for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes,\n j = 0, jj = nAttrs && nAttrs.length; j \u003c jj; j++) {\n var attrStartName = false;\n var attrEndName = false;\n\n```\n\nThis would enable me to implement so much additional functionality in a clean, concise, and for the sake of other developers on my project, abstractly. For example, suppose I'm using https://github.com/tenphi/angular-bem, and I want all components to also have a block\ndirective on them for simple, clean BEM notation. I could just do this:\n\n```\nfunction componentDecoratorConfig($compileProvider) {\n \"ngInject\";\n var oldProvider = $compileProvider.$get,\n oldComponent = $compileProvider.component;\n\n $compileProvider.component = registerComponent;\n\n function registerComponent(name, options) {\n options.$isComponent = true;\n return oldComponent.bind($compileProvider)(name, options);\n }\n\n $compileProvider.addNodeTransform(function(name, node) {\n if($injector.has(name + 'Directive') \n && $injector.get(name + 'Directive').controller.$isComponent) {\n node.attr.set('block', name);\n }\n return node;\n });\n```\n\nAnd voila! It's done! I'll admit that there are some parts of the compilation process that I don't fully get, and maybe this will have unintended consequences that I don't understand, but it seems like a simple solution to a problem that provides extensibility that is more generic that traditional specific directive decorators.\n\nThere was a similar pull request done by @lgalfaso , here: https://github.com/angular/angular.js/pull/6781, it seemed to have gotten some good feedback, but it was pretty involved, and it looks like it got shelved.\n\nI'd be glad to create a pull request, if I thought this functionality had any chance of being merged.\n\n-Aaron\n","author":{"url":"https://github.com/Aaron-Pool","@type":"Person","name":"Aaron-Pool"},"datePublished":"2016-10-14T16:22:17Z","url":"https://github.com/angular/angular.js/issues/15270"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1ae13b15-73d4-d59a-5aa3-3698f3ba2ffe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9DC:12ECEE:45905D:603117:6B047091 |
| html-safe-nonce | eca2b24c3552dccdcd6b3bd0477e9e7223a177c7968a020e01814a503bd51270 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOURDOjEyRUNFRTo0NTkwNUQ6NjAzMTE3OjZCMDQ3MDkxIiwidmlzaXRvcl9pZCI6Ijk0MTA1OTUyMTgxMzE3Nzc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1c0ea7132ac203ba6ce402ad097c743d06992542efeef2d594f5987bbfad7ebe |
| hovercard-subject-tag | issue:183092650 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular.js/15270/issue_layout |
| twitter:image | https://opengraph.githubassets.com/27a9671e7a773ab19545eb144e33aa112dbc394e90b275d2a26b3535568307f1/angular/angular.js/issues/15270 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/27a9671e7a773ab19545eb144e33aa112dbc394e90b275d2a26b3535568307f1/angular/angular.js/issues/15270 |
| og:image:alt | Do you want to request a feature or report a bug? Feature What is the current behavior? I have no way of modifying a node before the majority of compile functionality takes place (that I've found, ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Aaron-Pool |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular.js git https://github.com/angular/angular.js.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 460078 |
| octolytics-dimension-repository_nwo | angular/angular.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 460078 |
| octolytics-dimension-repository_network_root_nwo | angular/angular.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width