formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

feat(formly-form): formlyField.runExpressions resolve after fields ha… #699

Closed pseudo-su closed 8 years ago

pseudo-su commented 8 years ago

What

resolve promise from formlyField.runExpressions after fields have been set instead of $timeout promise

Why

$timeout promise will resolve before the async field setters have finished

How

using $q.all to resolve the promise after all the field setter promises are finished

For issue # 523

Checklist:

GitCop commented 8 years ago

There were the following issues with your Pull Request

Guidelines are available at https://github.com/formly-js/angular-formly/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

codecov-io commented 8 years ago

Current coverage is 95.89% (diff: 100%)

Merging #699 into master will increase coverage by 0.01%

@@             master       #699   diff @@
==========================================
  Files            17         17          
  Lines          1164       1169     +5   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           1116       1121     +5   
  Misses           48         48          
  Partials          0          0          

Sunburst

Powered by Codecov. Last update a4c54bb...6260cca

BarryThePenguin commented 8 years ago

Do you know if this change solves either of the skipped tests in formly-field.test.js

pseudo-su commented 8 years ago

@BarryThePenguin can't find any xit or xdescribe tests in the formly-field.test.js, am I missing something?

BarryThePenguin commented 8 years ago

Mocha uses test.skip

pseudo-su commented 8 years ago

"validateOnModelChange should run field expressions when form is initialised" test is possibly relevant but the test at the moment seems to be for non-promise situations. before it gets to the relevant part in FormlyFormController.runFieldExpressionProperties the field.runExpressions is undefined.

function runFieldExpressionProperties(field, index) {
    const model = field.model || $scope.model
    const promise = field.runExpressions && field.runExpressions()
    // field.runExpressions === undefined

Do you know when exactly there will be a promise and when there won't?

I'm not actually sure about the specifics which makes it difficult to write/adapt a test case without me spending some more time on it.

BarryThePenguin commented 8 years ago

Hmm... ok, I just thought they would solve those skipped tests. Sounds like it's a little more involved then

BarryThePenguin commented 8 years ago

Looks good. My only concern is there aren't any tests relying directly on this change. Should this be something to worry about?

pseudo-su commented 8 years ago

The relevant code in formly-field and formly-form controller do seem to be covered by some tests at least. Ideally there would be a test for making sure that expressions complete before validation, I'll look into it.

BarryThePenguin commented 8 years ago

Fantastic! That test fails before this PR and passes after, looks good to me

/cc @formly-js/angular-formly-collaborators got any input?

kentcdodds commented 8 years ago

This is great. Thanks for working on it. Any other reviewers wanna pitch in here? Should probably get at least one other.

kwypchlo commented 8 years ago

LGTM

BarryThePenguin commented 8 years ago

Thanks again for your help @psuedoSudo

kentcdodds commented 8 years ago

:clap:

pseudo-su commented 8 years ago

Glad I could help 😃