Labs/Jetpack/Reboot/JEP/114: Difference between revisions

 
(2 intermediate revisions by the same user not shown)
Line 17: Line 17:
=== Open Issues ===
=== Open Issues ===
* Currently Places Query API is in alpha stage, needs to be finished.
* Currently Places Query API is in alpha stage, needs to be finished.
* Which "observers" capabilities are required? Is it better to observe just a liveupdate result (in future) or all relevant changes to bookmarks and pages?
* The Query API does not act on temp tables for performance reasons, thus history results are cached on 2 minutes (this problem will go away as soon as we remove temp tables, that is targeted for FX4)
* The Query API does not act on temp tables for performance reasons, thus history results are cached on 2 minutes (this problem will go away as soon as we remove temp tables, that is targeted for FX4)
* Live updating results are not supported OOTB, these will come later as a wrapper around current Query API, and will most likely be exposed as .result(), similar to filter, but will return objects iteratable rather than simple static arrays.
* Live updating results are not supported OOTB, these will come later as a wrapper around current Query API, and will most likely be exposed as .result(), similar to filter, but will return objects iteratable rather than simple static arrays.
Line 44: Line 45:
=== Examples ===
=== Examples ===


'''Get module'''
This is a selection of possibilities, changing filtering can achieve many more actions.
<pre class="brush:js;toolbar:false;">
var places = require("places");
</pre>


'''Get module'''
'''Get module'''
Line 56: Line 54:
'''Filter history'''
'''Filter history'''
<pre class="brush:js;toolbar:false;">
<pre class="brush:js;toolbar:false;">
function callbackFunc(results) {
function callbackFunc(results) {
   // results is an array of ResultItem objects.
   // results is an array of ResultItem objects.
   // a 0-length results indicates there are no more results.
   // a 0-length results indicates there are no more results.
}
}
// See PlacesQuery for description of the query configuration object.
// See PlacesQuery for description of the query configuration object.
places.history.filter({ host: "^www.moz" }, callbackFunc, callbackScope);
places.history.filter({ host: "^www.moz" }, callbackFunc, callbackScope);
</pre>
</pre>


'''Filter bookmarks'''
'''Filter bookmarks'''
<pre class="brush:js;toolbar:false;">
<pre class="brush:js;toolbar:false;">
places.history.filter({ phrase: "search words" }, callbackFunc, callbackScope);
places.history.filter({ phrase: "search words" }, callbackFunc, callbackScope);
</pre>
</pre>


'''Filter pages'''
'''Filter pages'''
<pre class="brush:js;toolbar:false;">
<pre class="brush:js;toolbar:false;">
places.filter({ phrase: "search words" }, callbackFunc, callbackScope);
places.filter({ phrase: "search words" }, callbackFunc, callbackScope);
</pre>
</pre>


'''Clear history'''
'''Clear history'''
<pre class="brush:js;toolbar:false;">
<pre class="brush:js;toolbar:false;">
places.history.remove(callbackFunc, callbackScope);
places.history.remove(callbackFunc, callbackScope);
</pre>
</pre>


'''Remove pages from history'''
'''Remove pages from history'''
<pre class="brush:js;toolbar:false;">
<pre class="brush:js;toolbar:false;">
places.history.filter({ host: "remove.host.com" })
places.history.filter({ host: "remove.host.com" })
               .remove(callbackFunc, callbackScope);
               .remove(callbackFunc, callbackScope);
</pre>
'''Remove bookmarks'''
<pre class="brush:js;toolbar:false;">
places.bookmarks.filter({ bookmarked: { tags: ["removeme"] } })
                .remove(callbackFunc, callbackScope);
</pre>
'''Annotations'''
<pre class="brush:js;toolbar:false;">
// Add bookmark annotations. If the result is not required to be bookmarked,
// a page annotation is added instead.
places.bookmarks.filter({ uri: "^http://mozilla.org/annotateme/$" })
                .annotate([{ name: "annoToAdd", value: "annoValue" }],
                          myCallback, callbackScope);
// To remove an annotation omit value.
places.bookmarks.filter({ uri: "^http://mozilla.org/annotateme/$" })
                .annotate([{ name: "annoToAdd" }], myCallback, callbackScope);
// XXX to simplify this could just be .save({ annotations: [...] });
</pre>
'''Bookmarks'''
<pre class="brush:js;toolbar:false;">
// Add a bookmark.
places.bookmarks.save({ uri: "http://moz.org/"
                      , title: "a bookmark"
                      , parent: 3
                      , position: 12
                      }, myCallback, callbackScope);
// Edit a bookmark: set title, remove tag foo, add tag bar.
places.bookmarks.filter({ uri: "http://moz.org/"
                        , sort: { by: "time", dir: "desc" }
                        , limit: 1
                        }).save({ title: "a new title"
                                , tags: ["-foo", "bar"]
                                }, myCallback, callbackScope);
</pre>
</pre>
Confirmed users
595

edits