Skip to content

Instantly share code, notes, and snippets.

@jsantell
Created April 3, 2013 21:18
Show Gist options
  • Save jsantell/5305412 to your computer and use it in GitHub Desktop.
Save jsantell/5305412 to your computer and use it in GitHub Desktop.
Example usage of Places API
const { Bookmarks } = require('sdk/places/bookmarks');
const { all } = require('sdk/core/promise');
const { each } = require('sdk/util/array');
var data = [
{
url: 'http://www.mozilla.org',
title: 'Mozilla Org Homepage'},
{
url: 'http://bugzilla.mozilla.org',
title: 'Bugzilla'},
{
type: 'separator'},
{
url: 'https://github.com/mozilla',
title: 'GitHub'}
];
/*
* Creates a new bookmark folder and then
* adds 3 bookmarks and a separator into that folder
* using promises
*/
Bookmarks.create({
title: 'mozilla bookmarks',
type: 'folder'
}).then(createBookmarks).then(success, console.error);
/*
* Helpers
*/
function createBookmarks (parent) {
return all(each(data, applyParent(parent))
.map(Bookmarks.create));
}
function applyParent (parent) {
return function (data) { data.parent = parent.id; }
}
function success (bookmarks) {
bookmarks.forEach(function (bm) {
console.log(bm.type + ' added ' + bm.url);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment