Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Clean way to set all forms to pristine status
Message
De
31/01/2018 07:38:59
 
 
Information générale
Forum:
AngularJS
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01657612
Message ID:
01657622
Vues:
36
recursive pro: probably most stable across changes in working order of framework / implementation detail changes.
con: will incur minimally more runtime on execution as setPristine will drill down again into the sub-component "calling up"
probably mitigated by the caching / rendering function quality or hard coded $dirty check. Recursive behaviour better to be spelled out in method name, but depends on naming scheme prevalent in project.

Given that your code/fwk is based pure GUI behaviour, I'd probably have opted to find the correct upward form/node to start the waterfall action (could have been coded recursively, but a pure while is good enough and easier to grok months later in code) to find the correct $dirty/starting form and call setPristine there, trusting the drill-down logic. Same amount of brittleness/technical debt acrued as above, easier to debug for my kind of brain. Opting for best runtime perf when given similar amounts of resulting code and tech gruft, and if logs are created they are more human-understandable ;-)

When asked to sketch out an architecture, I'd steer away from such logic and drive all GUI via the VM, allowing different set/objects for

  • persistable biz data (SQL domain backend)
    semi-persistable user connected data (unsaved changes, screen layout, personal/machine settings free to each user)
    non-persistable GUI data to be recreated/revalidated on running again

  • but all to often the only recurse is to explain more effort needed after managment followed some high level bull$hit bingo ...


    >
    > DateTimePicker.prototype.setPristine = function () {
    >        if (this.form) {
    >            this.form.$setPristine();
    >
    >            if (this.form.$$parentForm.$dirty) {
    >                this.form.$$parentForm.$setPristine();
    >            }
    >            if (this.form.$$parentForm.$$parentForm && this.form.$$parentForm.$$parentForm.$dirty) {
    >                this.form.$$parentForm.$$parentForm.$setPristine();
    >            }
    >        }
    >    };
    >
    >I don't really like it. Is there a cleaner way to set everything to pristine from the bottom up?
    >
    >Thanks a lot in advance.
    >
    >UPDATE. Per suggestion in stackoverflow re-wrote the above as recursive function. Works quite nicely.
    Précédent
    Répondre
    Fil
    Voir

    Click here to load this message in the networking platform