Created
February 22, 2010 03:01
-
-
Save subtleGradient/310735 to your computer and use it in GitHub Desktop.
Mythical syntax experiment if there were other jQuery-esque DSLs for other things
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Do some more of the same sort of stuff with another DB search | |
| // Bind the DB to the UI | |
| MyDBDSL("#big") | |
| .change(function(){ | |
| var rows = MyDBDSL(this).rows(); | |
| jQuery("#products #big").removeClass('db-error') | |
| .find("form .db-invalid").removeClass('db-invalid').end() | |
| .find("table").html( rows.html() ); | |
| }) | |
| .error(function(){ | |
| jQuery("#products #big").addClass('db-error'); | |
| jQuery("#products #big form").find("input").filter( | |
| MyDBDSL(this).filter(":invalid").jQuery("toQuery") | |
| ).addClass("db-invalid"); | |
| }) | |
| ; | |
| // Bind the UI to the DB | |
| MyDBDSL("#big").rows('product[height>=46"], product[width>=46"], product[depth>=46"]'); | |
| jQuery("#products #big form").submit(function(){ | |
| var db_query = jQuery(this).MyDBDSL("toQuery","products"); // convert form data to query | |
| MyDBDSL("#big").rows( db_query ); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MyEmailDSL("message").from("me.work").to("john.home").body("Lorem ipsum…").send(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Find or create a DB search named "#light" | |
| // Bind its change event to update the View | |
| MyDBDSL("#light").change(function(){ | |
| // Get the new changed rows | |
| var rows = MyDBDSL(this).rows(); | |
| // Update the #products #light table with the rows data | |
| jQuery("#products #light table").html( rows.html() ); | |
| }); | |
| // Asynchronously Set the rows of the #light DB search | |
| // by querying the DB | |
| MyDBDSL("#light").rows("product[weight<=6kg]"); | |
| // Bind the #products form | |
| // to update the #light rows | |
| jQuery("#products #light form").submit(function(){ | |
| MyDBDSL("#light").rows("product[weight" + | |
| $(this).find("[name=operator]").value() + | |
| $(this).find("[name=weight]").value() + | |
| "]"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment