forked from remotestorage/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.js
43 lines (40 loc) · 1.21 KB
/
root.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(function() {
if(!RemoteStorage) {
RemoteStorage = remoteStorage;
}
RemoteStorage.defineModule('root', function(privClient, pubClient) {
function privPubFork(name, pathParamPos) {
if(! pathParamPos) {
pathParamPos = 0;
}
return function() {
var args = util.toArray(arguments);
var path = args[pathParamPos];
if(path.substr(8) === '/public/') {
return pubClient[name].apply(pubClient, args);
} else {
return privClient[name].apply(privClient, args);
}
}
}
return {
exports: {
on: function(eventName, handler) {
privClient.on(eventName, handler);
pubClient.on(eventName, handler);
},
use: privPubFork('use'),
release: privPubFork('release'),
getListing: privPubFork('getListing'),
getAll: privPubFork('getAll'),
getObject: privPubFork('getObject'),
getFile: privPubFork('getFile'),
storeObject: privPubFork('storeObject', 1),
storeFile: privPubFork('storeFile', 1),
remove: privPubFork('remove'),
hasDiff: privPubFork('hasDiff'),
getItemURL: privPubFork('getItemURL')
}
};
});
})();