Files
panic-server/patch.js
Jesse Gibson a601ec9da9 Implemented interval option, better defaults and a bug fix.
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 :(
2015-12-17 23:50:59 -07:00

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;
}