Created
April 3, 2013 21:18
-
-
Save jsantell/5305412 to your computer and use it in GitHub Desktop.
Example usage of Places API
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
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