diff --git a/.gitignore b/.gitignore index 09c0f90..49ad610 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ browsertest/bundle.js examples/**/components examples/**/bower_components scratchpad.coffee +*.map \ No newline at end of file diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000..019c3d3 --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,22 @@ +## Changelog + +### 0.5.0 + +- remove hard dependency on jQuery (allows you to use ZeptoJS, EnderJS or a similar alternative) +- rename to *bacon-dom* +- allow init() function to be called without $ having been defined +- introduce: Bacon.$.Selector, Bacon.$.Request and Bacon.$.Promise for better customization +- requires `.toJQC(x)` method on JQC (i.e `$` selector) + +- Bacon.$.Selector, Bacon.$.Request and Bacon.$.Promise can be set at any time to point to + jQuery compatible APIs (similar to jQuery $) + +- Bacon.$.Selector must just point to a function which given a selector string can find an element + +- Bacon.$.Request must just point to an object with a jQuery compatible `ajax` method + +- Bacon.$.Promise can alternatively be set to any Promise/A+ compatible lib. + It will to use `deferred()` and fall-back to `Deferred()` + It will then use `notify()`, `resolve()` and `reject()` on the deferred + +- Changed dom-inputvalue to use API such as `Bacon.$.select.value` and `Bacon.$.radioGroup.intValue` \ No newline at end of file diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 2d96f0c..7ca2ae5 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -6,12 +6,12 @@ module.exports = (grunt) -> coffee: compile: - files: ["dist/bacon.jquery.js": "src/bacon.jquery.coffee"] + files: ["dist/bacon-dom.js": "src/*.coffee"] uglify: dist: - src: "dist/bacon.jquery.js" - dest: "dist/bacon.jquery.min.js" + src: "dist/bacon-dom.js" + dest: "dist/bacon-dom.min.js" grunt.loadNpmTasks "grunt-contrib-coffee" grunt.loadNpmTasks "grunt-contrib-clean" diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..6d6abbf --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,34 @@ +// Generated by CoffeeScript 1.8.0 +(function() { + module.exports = function(grunt) { + grunt.initConfig({ + clean: { + dist: ["dist/"], + coffee: ["dist/*.coffee"] + }, + coffee: { + compile: { + files: [ + { + "dist/bacon-dom.js": "src/*.coffee" + } + ] + } + }, + uglify: { + dist: { + src: "dist/bacon-dom.js", + dest: "dist/bacon-dom.min.js" + } + } + }); + grunt.loadNpmTasks("grunt-contrib-coffee"); + grunt.loadNpmTasks("grunt-contrib-clean"); + grunt.loadNpmTasks("grunt-contrib-uglify"); + grunt.registerTask("build", ["clean:dist", "coffee", "uglify", "clean:coffee"]); + return grunt.registerTask("default", ["build"]); + }; + +}).call(this); + +//# sourceMappingURL=Gruntfile.js.map diff --git a/Gruntfile.js.map b/Gruntfile.js.map new file mode 100644 index 0000000..7fafa2e --- /dev/null +++ b/Gruntfile.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "Gruntfile.js", + "sourceRoot": "", + "sources": [ + "Gruntfile.coffee" + ], + "names": [], + "mappings": ";AAAA;AAAA,EAAA,MAAM,CAAC,OAAP,GAAiB,SAAC,KAAD,GAAA;AACf,IAAA,KAAK,CAAC,UAAN,CACE;AAAA,MAAA,KAAA,EACE;AAAA,QAAA,IAAA,EAAM,CAAC,OAAD,CAAN;AAAA,QACA,MAAA,EAAQ,CAAC,eAAD,CADR;OADF;AAAA,MAIA,MAAA,EACE;AAAA,QAAA,OAAA,EACE;AAAA,UAAA,KAAA,EAAO;YAAC;AAAA,cAAA,mBAAA,EAAqB,cAArB;aAAD;WAAP;SADF;OALF;AAAA,MAQA,MAAA,EACE;AAAA,QAAA,IAAA,EACE;AAAA,UAAA,GAAA,EAAK,mBAAL;AAAA,UACA,IAAA,EAAM,uBADN;SADF;OATF;KADF,CAAA,CAAA;AAAA,IAcA,KAAK,CAAC,YAAN,CAAmB,sBAAnB,CAdA,CAAA;AAAA,IAeA,KAAK,CAAC,YAAN,CAAmB,qBAAnB,CAfA,CAAA;AAAA,IAgBA,KAAK,CAAC,YAAN,CAAmB,sBAAnB,CAhBA,CAAA;AAAA,IAiBA,KAAK,CAAC,YAAN,CAAmB,OAAnB,EAA4B,CAAC,YAAD,EAAe,QAAf,EAAyB,QAAzB,EAAmC,cAAnC,CAA5B,CAjBA,CAAA;WAkBA,KAAK,CAAC,YAAN,CAAmB,SAAnB,EAA8B,CAAC,OAAD,CAA9B,EAnBe;EAAA,CAAjB,CAAA;AAAA" +} \ No newline at end of file diff --git a/README.md b/README.md index 0b61074..b68b637 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,37 @@ -# bacon.jquery +# bacon-dom -A JQuery data binding library for [Bacon.js](https://github.com/baconjs/bacon.js). +A JQuery compatible (JQC) data binding library for [Bacon.js](https://github.com/baconjs/bacon.js). -Adds stuff to `Bacon.$`. Is also called BJQ. +See fx [Ender.js](http://enderjs.com/#docs) `$._select` which you can use with [qwery](https://github.com/ded/qwery) + +```js +$._select = mySelectorEngine +$('#foo .bar') +``` + +See [example](https://github.com/ded/qwery/blob/master/src/ender.js) + +[Zepto.js](http://zeptojs.com/) is another powerful jQuery alternative... + +This library adds stuff to `Bacon.$`. It is also called "Baquery" (pronounced like "bakery"). Includes - Binding the state of HTML input elements to [`Bacon.Model`](https://github.com/baconjs/bacon.model) objects that extend the Bacon.js `Property` API by providing a bidirectional binding -- AJAX helpers. Wrap a JQuery AJAX call into an EventStream using +- AJAX helpers. Wrap a JQC AJAX call into an EventStream using `Bacon.$.ajax("/get/stuff")`. Convert an `EventStream` of requests into an `EventStream` of responses like `requests.ajax()`. -- FRP extensions to JQuery. Wrap JQuery events easily into an `EventStream`, as +- FRP extensions to JQC API. Wrap JQC events easily into an `EventStream`, as in `$("body").clickE()` -This library is intended as a replacement for [Bacon.UI](https://github.com/raimohanska/Bacon.UI.js). It provides the same functionality, with the addition of two-way bound Models, model composition and lenses. +This library is a replacement for [Bacon.UI](https://github.com/raimohanska/Bacon.UI.js). + +It provides the same functionality, with the addition of two-way bound Models, model composition and lenses. ## Example Applications -There are example applications in the [examples](https://github.com/baconjs/bacon.jquery/tree/master/examples) directory, each with a README.md describing how they are started. +There are example applications in the [examples](https://github.com/baconjs/bacon-dom/tree/master/examples) directory, each with a README.md describing how they are started. Each application does essentially the same thing and the code in the example applications is essentially just this: @@ -38,32 +51,51 @@ Each application does essentially the same thing and the code in the example app ## API -The `bacon.jquery` API consists of methods for creating a `Model` representing the +The `bacon-dom` API consists of methods for creating a `Model` representing the state of a DOM element or a group of DOM elements. This API is published as `Bacon.$`, and the same object is returned when using AMD or CommonJS. +Note: The optional initiValue has now been replaced with an (optional) options hash. +Instead of `Bacon.$.textFieldValue(field, '')` use `Bacon.$.textFieldValue(field, {init: ''})`. +This is to allow for more flexibility down the line... + +### Plugins + + +- `ajax` +- `dom-input` +- `effects` +- `events` +- `promise` (deferred) + +Use `Bacon.$.plugin('dom-input', 'ajax')` to add the plugins you want to enable. + +### DOM Input + +`Bacon.$.addPlugin('dom-input')` + ###Bacon.$.textFieldValue(field [, initValue]) Creates a `Model` for an -`` element, given as a JQuery object. You can optionally supply an initial value. +`` element, given as a JQC object. You can optionally supply an initial value. ###Bacon.$.checkBoxValue(field [, initValue]) Creates a `Model` for a -`` element, given as a JQuery object. The value is `true` if the checkbox is checked and +`` element, given as a JQC object. The value is `true` if the checkbox is checked and `false` otherwise. ###Bacon.$.selectValue(field [,initValue]) Creates a `Model` for a `` elements, given as a JQuery object or an Array -of jQuery objects. The value of the model corresponds to the `value` attribute +group of `` elements, given as a JQC object/Array. +The value of the model corresponds to the `value` attribute of the selected radio input element. Note that `value` is a string. ###Bacon.$.intRadioGroupValue(fields [, initValue]) @@ -73,17 +105,16 @@ Like `Bacon.$.radioGroupValue`, but for integer values. ###Bacon.$.checkBoxGroupValue(fields, [,initValue]) Creates a `Model` for a group -of `` elements, given as a JQuery object or an Array of -jQuery objects. The value of the model is an array of the `value` attributes of +of `` elements, given as a JQC object/Array . The value of the model is an array of the `value` attributes of the checked checkbox input elements. For instance, if you have checkboxes and 2 of these are checked, having values `a` and `b`, the value of the Model is `["a", "b"]`. TODO: add HTML/JS examples -## FRP extensions to JQuery Events +## FRP extensions to JQC Events -BJQ adds methods to JQuery, for wrapping events into an `EventStream`. +BJQ adds methods to JQC, for wrapping events into an `EventStream`. For example, to wrap click events on `` into an `EventStream`, you can @@ -123,9 +154,9 @@ Supported methods include the following: - loadE - unloadE -## FRP extensions to JQuery Effects +## FRP extensions to JQC Effects -BJQ adds methods to JQuery, for performing animations and wrapping the +BJQ adds methods to JQC, for performing animations and wrapping the result `Promise` into an `EventStream`. For example var fadeOut = $("#thing").fadeOutE("fast") @@ -146,7 +177,7 @@ Supported methods include the following: ## AJAX -BJQ provides helpers for JQuery AJAX. All the methods return an +BJQ provides helpers for JQC AJAX. All the methods return an `EventStream` of AJAX results. AJAX errors are mapped into `Error` events in the stream. @@ -196,25 +227,21 @@ Turns your Bacon Ajax stream back to $.Deferred. It's useful if you need to prov ## Model API -All the BJQ methods, such as `textFieldValue` return a `Model` object, which is a Bacon.js `Property`, but extends that API by the following methods. - -[Model API reference migrated to bacon.model](https://github.com/baconjs/bacon.model) - - -TODO: more +All the BJQ methods, such as `textFieldValue` return a `Model` object, which is a Bacon.js `Property`, +but extends that API with [bacon.model](https://github.com/baconjs/bacon.model) methods ## Use with AMD / RequireJS -The [requirejs example-app](https://github.com/baconjs/bacon.jquery/tree/master/examples/requirejs) uses RequireJS, like this: +The [requirejs example-app](https://github.com/baconjs/bacon-dom/tree/master/examples/requirejs) uses RequireJS, like this: ```js require.config({ paths: { - "bacon.jquery": "../dist/bacon.jquery", + "bacon-dom": "../dist/bacon-dom", "bacon": "components/bacon/dist/Bacon", "jquery": "components/jquery/jquery" }}) -require(["bacon.jquery", "jquery"], function(bjq, $) { +require(["bacon-dom", "jquery"], function(bjq, $) { left = bjq.textFieldValue($("#left")) right = bjq.textFieldValue($("#right")) right.bind(left) @@ -222,36 +249,38 @@ require(["bacon.jquery", "jquery"], function(bjq, $) { }) ``` -The prebuilt javascript file can be found in the `dist` directory, or [here](https://raw.github.com/baconjs/bacon.jquery/master/dist/Bacon.JQuery.Bindings.js). +Note: You can substitute jquery with Zepto or any other compatible library ;) + +The prebuilt javascript file can be found in the `dist` directory, or [here](https://raw.github.com/baconjs/bacon-dom/master/dist/bacon-dom.Bindings.js). The API can be accessed using `Bacon.$` or like in the above example. ## Use without AMD -The [plain example-app](https://github.com/baconjs/bacon.jquery/tree/master/examples/plain) uses RequireJS, like this: +The [plain example-app](https://github.com/baconjs/bacon-dom/tree/master/examples/plain) uses RequireJS, like this: -So feel free to use plain old ` @@ -10,7 +10,7 @@ - + - +