Skip to content

Commit

Permalink
Merge pull request #420 from stutrek/master
Browse files Browse the repository at this point in the history
fix cursor error in Safari
  • Loading branch information
pubkey authored Jan 21, 2021
2 parents a5c6848 + 2c1b195 commit 8cb5c18
Show file tree
Hide file tree
Showing 25 changed files with 621 additions and 233 deletions.
39 changes: 28 additions & 11 deletions dist/es/broadcast-channel.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { isPromise } from './util.js';
import { chooseMethod } from './method-chooser.js';
import { fillOptionsWithDefaults } from './options.js';
export var BroadcastChannel = function BroadcastChannel(name, options) {
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clearNodeFolder = clearNodeFolder;
exports.enforceOptions = enforceOptions;
exports.BroadcastChannel = void 0;

var _util = require("./util.js");

var _methodChooser = require("./method-chooser.js");

var _options = require("./options.js");

var BroadcastChannel = function BroadcastChannel(name, options) {
this.name = name;

if (ENFORCED_OPTIONS) {
options = ENFORCED_OPTIONS;
}

this.options = fillOptionsWithDefaults(options);
this.method = chooseMethod(this.options); // isListening
this.options = (0, _options.fillOptionsWithDefaults)(options);
this.method = (0, _methodChooser.chooseMethod)(this.options); // isListening

this._iL = false;
/**
Expand Down Expand Up @@ -49,15 +61,17 @@ export var BroadcastChannel = function BroadcastChannel(name, options) {
* See methods/native.js
*/


exports.BroadcastChannel = BroadcastChannel;
BroadcastChannel._pubkey = true;
/**
* clears the tmp-folder if is node
* @return {Promise<boolean>} true if has run, false if not node
*/

export function clearNodeFolder(options) {
options = fillOptionsWithDefaults(options);
var method = chooseMethod(options);
function clearNodeFolder(options) {
options = (0, _options.fillOptionsWithDefaults)(options);
var method = (0, _methodChooser.chooseMethod)(options);

if (method.type === 'node') {
return method.clearNodeFolder().then(function () {
Expand All @@ -72,11 +86,14 @@ export function clearNodeFolder(options) {
* no mather what the options are
*/


var ENFORCED_OPTIONS;
export function enforceOptions(options) {

function enforceOptions(options) {
ENFORCED_OPTIONS = options;
} // PROTOTYPE


BroadcastChannel.prototype = {
postMessage: function postMessage(msg) {
if (this.closed) {
Expand Down Expand Up @@ -162,7 +179,7 @@ function _post(broadcastChannel, type, msg) {
function _prepareChannel(channel) {
var maybePromise = channel.method.create(channel.name, channel.options);

if (isPromise(maybePromise)) {
if ((0, _util.isPromise)(maybePromise)) {
channel._prepP = maybePromise;
maybePromise.then(function (s) {
// used in tests to simulate slow runtime
Expand Down
8 changes: 5 additions & 3 deletions dist/es/browserify.index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var module = require('./index.es5.js');
"use strict";

var BroadcastChannel = module.BroadcastChannel;
var createLeaderElection = module.createLeaderElection;
var _module = require('./index.es5.js');

var BroadcastChannel = _module.BroadcastChannel;
var createLeaderElection = _module.createLeaderElection;
window['BroadcastChannel2'] = BroadcastChannel;
window['createLeaderElection'] = createLeaderElection;
13 changes: 8 additions & 5 deletions dist/es/index.es5.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"use strict";

var _index = require("./index.js");

/**
* because babel can only export on default-attribute,
* we use this for the non-module-build
Expand All @@ -6,10 +10,9 @@
* but
* var BroadcastChannel = require('broadcast-channel');
*/
import { BroadcastChannel, createLeaderElection, clearNodeFolder, enforceOptions } from './index.js';
module.exports = {
BroadcastChannel: BroadcastChannel,
createLeaderElection: createLeaderElection,
clearNodeFolder: clearNodeFolder,
enforceOptions: enforceOptions
BroadcastChannel: _index.BroadcastChannel,
createLeaderElection: _index.createLeaderElection,
clearNodeFolder: _index.clearNodeFolder,
enforceOptions: _index.enforceOptions
};
35 changes: 33 additions & 2 deletions dist/es/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
export { BroadcastChannel, clearNodeFolder, enforceOptions } from './broadcast-channel';
export { createLeaderElection } from './leader-election';
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "BroadcastChannel", {
enumerable: true,
get: function get() {
return _broadcastChannel.BroadcastChannel;
}
});
Object.defineProperty(exports, "clearNodeFolder", {
enumerable: true,
get: function get() {
return _broadcastChannel.clearNodeFolder;
}
});
Object.defineProperty(exports, "enforceOptions", {
enumerable: true,
get: function get() {
return _broadcastChannel.enforceOptions;
}
});
Object.defineProperty(exports, "createLeaderElection", {
enumerable: true,
get: function get() {
return _leaderElection.createLeaderElection;
}
});

var _broadcastChannel = require("./broadcast-channel");

var _leaderElection = require("./leader-election");
25 changes: 18 additions & 7 deletions dist/es/leader-election.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { sleep, randomToken } from './util.js';
import unload from 'unload';
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createLeaderElection = createLeaderElection;

var _util = require("./util.js");

var _unload = _interopRequireDefault(require("unload"));

var LeaderElection = function LeaderElection(channel, options) {
this._channel = channel;
this._options = options;
this.isLeader = false;
this.isDead = false;
this.token = randomToken();
this.token = (0, _util.randomToken)();
this._isApl = false; // _isApplying

this._reApply = false; // things to clean up
Expand Down Expand Up @@ -57,12 +67,12 @@ LeaderElection.prototype = {

var ret = _sendMessage(this, 'apply') // send out that this one is applying
.then(function () {
return sleep(_this._options.responseTime);
return (0, _util.sleep)(_this._options.responseTime);
}) // let others time to respond
.then(function () {
if (stopCriteria) return Promise.reject(new Error());else return _sendMessage(_this, 'apply');
}).then(function () {
return sleep(_this._options.responseTime);
return (0, _util.sleep)(_this._options.responseTime);
}) // let others time to respond
.then(function () {
if (stopCriteria) return Promise.reject(new Error());else return _sendMessage(_this);
Expand Down Expand Up @@ -176,7 +186,8 @@ function _sendMessage(leaderElector, action) {

function _beLeader(leaderElector) {
leaderElector.isLeader = true;
var unloadFn = unload.add(function () {

var unloadFn = _unload["default"].add(function () {
return leaderElector.die();
});

Expand Down Expand Up @@ -210,7 +221,7 @@ function fillOptionsWithDefaults(options, channel) {
return options;
}

export function createLeaderElection(channel, options) {
function createLeaderElection(channel, options) {
if (channel._leaderElector) {
throw new Error('BroadcastChannel already has a leader-elector');
}
Expand Down
38 changes: 26 additions & 12 deletions dist/es/method-chooser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import NativeMethod from './methods/native.js';
import IndexeDbMethod from './methods/indexed-db.js';
import LocalstorageMethod from './methods/localstorage.js';
import SimulateMethod from './methods/simulate.js';
import { isNode } from './util'; // order is important

var METHODS = [NativeMethod, // fastest
IndexeDbMethod, LocalstorageMethod];
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.chooseMethod = chooseMethod;

var _native = _interopRequireDefault(require("./methods/native.js"));

var _indexedDb = _interopRequireDefault(require("./methods/indexed-db.js"));

var _localstorage = _interopRequireDefault(require("./methods/localstorage.js"));

var _simulate = _interopRequireDefault(require("./methods/simulate.js"));

var _util = require("./util");

// order is important
var METHODS = [_native["default"], // fastest
_indexedDb["default"], _localstorage["default"]];
/**
* The NodeMethod is loaded lazy
* so it will not get bundled in browser-builds
*/

if (isNode) {
if (_util.isNode) {
/**
* we use the non-transpiled code for nodejs
* because it runs faster
Expand All @@ -31,13 +45,13 @@ if (isNode) {
}
}

export function chooseMethod(options) {
function chooseMethod(options) {
var chooseMethods = [].concat(options.methods, METHODS).filter(Boolean); // directly chosen

if (options.type) {
if (options.type === 'simulate') {
// only use simulate-method if directly chosen
return SimulateMethod;
return _simulate["default"];
}

var ret = chooseMethods.find(function (m) {
Expand All @@ -51,7 +65,7 @@ export function chooseMethod(options) {
*/


if (!options.webWorkerSupport && !isNode) {
if (!options.webWorkerSupport && !_util.isNode) {
chooseMethods = chooseMethods.filter(function (m) {
return m.type !== 'idb';
});
Expand Down
3 changes: 2 additions & 1 deletion dist/es/methods/cookies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* if you really need this method,
* implement it
*/
*/
"use strict";
Loading

0 comments on commit 8cb5c18

Please sign in to comment.