Giter Site home page Giter Site logo

Comments (6)

daffl avatar daffl commented on August 20, 2024

Except for some special cases a JavaScript object will usually be traversed in the order it has been defined.
But you are right, it would totally make sense to be able to define dependencies.
I am just not sure what the best way to implement that would be...

from jquery.dform.

six8 avatar six8 commented on August 20, 2024

I had this for options:

years = {
  '': '',
  2012: 2012,
  2011: 2011,
  etc
}

When passed to options the sort couldn't be predicted. I had to use a list with [{ value: 2012, html: 2012}...] for options to ensure order was maintained. This is clearly one of those cases where order isn't maintained. This case generally doesn't appear in config options. However, it's an obscure problem that isn't obvious to casual observers.

I think the only way to do it would be to give each subscriber some sort of priority and apply them in that order or to maintain a list of the order to apply them. This would of course be a pain in the ass. You can also allow each subscriber to define an "after" subscriber for which you can determine dependency order, but that's a bit complicated too. I'll think about it and see if I can come up with a simpler option and send you a pull request.

from jquery.dform.

daffl avatar daffl commented on August 20, 2024

That is exactly the case where it doesn't work. V8 (Chrome) orders by the actual value, all the others when it has been defined. Unfortunately there is not much that can be done about that (except for being able to pass an array to the options value for years).
For the actual dependencies I was thinking about something like that:

$.dform.subscribe('value', function(options) {
    this.val(options);
}, ['options']);

This would assure that the options subscriber is run before if an option key exists.

from jquery.dform.

six8 avatar six8 commented on August 20, 2024

Looks good. I thought it would be fun to figure out a simple dependency graph in JS https://gist.github.com/1732686

from jquery.dform.

six8 avatar six8 commented on August 20, 2024

I found a much simpler way to do a topological sort on a graph so I updated the gist.

from jquery.dform.

daffl avatar daffl commented on August 20, 2024

This looks great, thanks! I will work on it on the weekend and hopefully get 0.1.4 finished up and released with the fix.

from jquery.dform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.