JohnLouderback / GDB

Generic Data Binder (GDB) for jQuery is a framework agnostic and extremely easy to use 2 way data binder. GDB binds views and models in realtime with live two-way binding and no hefty framework necessary.
http://gdb.thewebdev.guru/
Apache License 2.0
87 stars 11 forks source link

Get a model back as plain JSON. #12

Closed nevf closed 10 years ago

nevf commented 10 years ago

GDB changes a model so it is no longer a plain Javascript object which of course it has to. However I can't see a method to convert back to a plain JS object. I'm using:

var o_model = JSON.parse( JSON.stringify( model ) );

Am I missing something? If not how about adding a plainModel( model ) function to GDB to do this.

JohnLouderback commented 10 years ago

Hi Neville,

This is strange to hear. Interestingly enough, GDB doesn't do any conversions to the object you feed it. GDB only uses the object you supply to it as a reference and not a copy. I do believe the Object.observe() polyfill GDB uses does add some getter and setter methods, but I believe that's it. If your model was JSON stringifiable in the first place, it should remain so. Perhaps I misunderstand your question though. If I don't understand, could you please show me a commented example of the behavior?

Thanks, -John

JohnLouderback commented 10 years ago

If you meant that you'd like GDB to convert complex models to plain JavaScript object literals, I could make a method that does this, if you'd like.

nevf commented 10 years ago

Hi John, Yes it was the setter & getter methods that had me confused. This does indeed work fine as is, however a function to get plain JS object literal would probably be worthwhile.

JohnLouderback commented 10 years ago

I may add this feature in the future, but not today. If this feature is very important to Clibu, I can consider adding it much sooner. Let me know and I'll see what I can do. Perhaps I'll add this as an additional module as to not bloat the main library too much.