mirror of
https://github.com/gundb/panic-server.git
synced 2026-05-07 03:00:26 -04:00
Interval option built with a recursive setTimeout (not setInterval) that tracks it's invoked number. Patch function now determines it's own ID if it isn't provided, meaning that the opts-must-be-object requirement isn't needed. In other words, all options are optional (wow). Bug fix: minor thing where I was using gun before it was defined. This was due to minor tweaking just before a commit and not having unit tests to shout at me :(
34 lines
593 B
JavaScript
34 lines
593 B
JavaScript
/*globals Gun*/
|
|
/*
|
|
Expect an object like this:
|
|
|
|
|
|
var thing = {
|
|
interval: Number,
|
|
peers: Array,
|
|
amount: Number,
|
|
id: String,
|
|
key: String,
|
|
path: String,
|
|
data: *
|
|
};
|
|
|
|
*/
|
|
|
|
function patch(opt) {
|
|
'use strict';
|
|
var url = location.protocol + '//';
|
|
url += location.host;
|
|
url += '/gun';
|
|
|
|
opt = opt || {};
|
|
opt.key = opt.key || 'panic/test/';
|
|
opt.interval = opt.interval || 0;
|
|
opt.peers = opt.peers || [url];
|
|
opt.amount = opt.amount || 300;
|
|
opt.id = opt.id || Gun.text.random();
|
|
opt.path = opt.path || Gun.text.random();
|
|
opt.data = opt.data || Gun.text.random();
|
|
return opt;
|
|
}
|