-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Directive scopeTypes like react's propTypes #11657
Comments
I like this idea but I am concerned about the performance implications and how it could actually be implemented. Each of the directive "bindings", i.e. the scope or bindToController properties, are updated independently triggered by various watches that are set up a linking time. So I would expect that this validation hook would need to be triggered for individual bindings as their watch handler is triggered. What do others think? |
Yeah, I'll give more input later (parked now to respond quickly). But I've https://github.com/alianza-dev/angular-scope-types
(Sent from my mobile device, please forgive typos or brevity)
|
Also, the tests could probably be written a little more clearly so you
(Sent from my mobile device, please forgive typos or brevity)
|
I've updated the documentation to describe how to use my library. But if this were implemented directly into angular the API would be much better (wouldn't have to do most of the stuff... It's just the https://github.com/alianza-dev/angular-scope-types Also updated the demo so you can play with it: https://jsbin.com/kuqeye/edit?html,js,output |
@kentcdodds if you could put together a very basic PR with a Proof of Concept for what the API would look like and how it would not impact production performance then I would be happy to discuss including it. |
Fantastic! Would love to get something like this supported in core. Do you mind giving me a tip as to a good place to start? As well as where my tests should go? |
The unit tests go in the test folder :-) If you are modifying the |
Add happy path tests and initial implementation for directive scopeTypes angular#11657
@petebacondarwin, I've finally made my first commit for this feature. Looking for feedback. I'm certain this isn't exactly how you want it implemented, but it shows the general idea of what I'm going after and what I'd expect. Also, I'm not sure why, but doing this breaks other (seemingly unrelated) tests. They fail with something like:
Not sure what's going on there, but if you Looking for feedback and direction so I can iterate on this. |
+1 this is a great idea and is something that's needed in Angular 1 |
since we're getting a Schema (angular/angular#2014) feature in Angular 2 perhaps we can do something similar for Angular 1 |
@kentcdodds I left some feedback on your commit. |
Great effort ! |
Thanks @fabm22. I'd love to work on this more, but I don't think that I'll actually be able to make this happen. I hope it does get implemented eventually, but I don't think that I'll be the one developing it :-( |
I take @kentcdodds idea and a bit rewrite it. cawabunga/angular.js@g3_v1_5...cawabunga:feature-directive-scope-validation |
This is great to see! |
I have few conceptual questions. |
I would expect validation to happen every time a
Just log a warning to the console.
Doesn't your implementation show how to configure it? You have some tests that seem reasonable to me ¯_(ツ)_/¯ Or are you talking about app-level configuration? I don't see any reason to have app-level config. Full disclosure: I don't work in angular codebases anymore, so my opinions should not really be considered for much :-) |
One of my favorite parts of React is PropTypes. I would really really love to be able to utilize this kind of api in Angular.
For those not familiar, PropTypes essentially allows you to validate the api to your component so the developer is warned in the console when providing properties that are incorrect, of the wrong type, or are required and not specified.
I love this so much that I created apiCheck.js to bring this to the VanillaJS world. And I even started a little prototype (WIP) for adding scopeTypes to Angular 1.x directives.
I would happily work on adding this functionality to angular if there's enough interest. Even something as simple as a function that would be called to validate the scope properties would be nice... Just keeping validation out of my controller logic is what I'm looking for.
Note: I'm more interested in getting this concept accepted and implemented than I am in actually using apiCheck... I don't care what's used. I just want it to be easy.
The text was updated successfully, but these errors were encountered: