Skip to content

Instantly share code, notes, and snippets.

@ironchefpython
Created June 30, 2011 17:29
Show Gist options
  • Save ironchefpython/1056720 to your computer and use it in GitHub Desktop.
Save ironchefpython/1056720 to your computer and use it in GitHub Desktop.
Idioms for updating properties with weld

Here are the options I've thought about for attribute update syntax


Option 1. Certain types of html elements where the most common use case is attribute update, such as <img>, <iframe>, <input>, <link>, <object>, <param>... and <a> update the logical attribute by default.

    $('<a id="target" href="http://yahoo.com"><span id="text">Yahoo</span></a>')
        .weld({target:'http://google.com', text: 'Google'});

Option 2. Attribute to update is a configuration option

    var config = {setattr: {a: 'href'}};
    $('<a id="target" href="http://yahoo.com"><span id="text">Yahoo</span></a>')
        .weld({target:'http://google.com', text: 'Google'}, config);

Option 3. Attribute to update is indicated in the HTML.

    $('<a id="target" data-weld-attr="href" href="http://yahoo.com">' + 
                                         '<span id="text">Yahoo</span></a>')
        .weld({target:'http://google.com', text: 'Google'});

Option 4. Attribute to update is indicated in the data object. (the '$' is a placeholder for the attribute separator character)

    $('<a id="target" href="http://yahoo.com">Yahoo</a>')
        .weld({target$href:'http://google.com', target: 'Google'});
@tmpvar
Copy link

tmpvar commented Jul 1, 2011

I would prefer not to create a microlanguage here.. the other option is to use map/alias :)

@ironchefpython
Copy link
Author

I understand your concern. I'll implement #4 for my own purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment