Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update existing JSON object instead of new one #34

Open
michael-lang opened this issue Feb 19, 2012 · 0 comments
Open

Update existing JSON object instead of new one #34

michael-lang opened this issue Feb 19, 2012 · 0 comments

Comments

@michael-lang
Copy link

Thanks for the great script!

I am working on an asynchronous user interface application. I have a json object along with read-only and edit templates on the client. When the user invokes edit I can show the edit form instantly. I am now working on showing the new read-only view after the user hits save (with the new edited values) immediately. I found your code as a good solution for building that new JSON object to pass into the template engine.

I've made a local copy change to make the main methods take in a json object instead of creating a new one and it works. Do you think it is a fit in your project?

from this:

function form2js(rootNode, delimiter, skipEmpty, nodeCallback, useIdIfEmptyName){
}
function processNameValues(nameValues, skipEmpty, delimiter)
{
    var result = {},
    ...
    return result;
}

to this:

function form2js(rootNode, json, delimiter, skipEmpty, nodeCallback, useIdIfEmptyName)
{
    //... only change is to pass in new 'json' value to processNameValues ...
}
function processNameValues(json, nameValues, skipEmpty, delimiter)
{
    //... only change is to set values on 'json' parameter instead of 'result' variable
    return json;
}

you could still have an 'overload' for the current use case that just calls into the new method interface. That would keep the script backwards compatible and add only a couple lines of code to the file.

function form2js(rootNode, delimiter, skipEmpty, nodeCallback, useIdIfEmptyName)
{
    return form2js(rootNode, {}, delimiter, skipEmpty, nodeCallback, useIdIfEmptyName);
}
function processNameValues(nameValues, skipEmpty, delimiter)
{
    return processNameValues({}, nameValues, skipEmpty, delimiter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant