Skip to content

Commit

Permalink
0.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
imaustink committed Nov 2, 2017
1 parent 7c5cccc commit 38c89b5
Show file tree
Hide file tree
Showing 17 changed files with 869 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dist/amd/can-globals-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*can-globals@0.2.5#can-globals-instance*/
define([
'require',
'exports',
'module',
'can-namespace',
'./can-globals-proto'
], function (require, exports, module) {
(function (global) {
'use strict';
var namespace = require('can-namespace');
var Globals = require('./can-globals-proto');
var globals = new Globals();
if (namespace.globals) {
throw new Error('You can\'t have two versions of can-globals, check your dependencies');
} else {
module.exports = namespace.globals = globals;
}
}(function () {
return this;
}()));
});
133 changes: 133 additions & 0 deletions dist/amd/can-globals-proto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*can-globals@0.2.5#can-globals-proto*/
define([
'require',
'exports',
'module',
'can-reflect'
], function (require, exports, module) {
(function (global) {
'use strict';
var canReflect = require('can-reflect');
function dispatch(key) {
var handlers = this.eventHandlers[key];
if (handlers) {
var handlersCopy = handlers.slice();
var value = this.getKeyValue(key);
for (var i = 0; i < handlersCopy.length; i++) {
handlersCopy[i](value);
}
}
}
function Globals() {
this.eventHandlers = {};
this.properties = {};
}
Globals.prototype.define = function (key, value, enableCache) {
if (enableCache === undefined) {
enableCache = true;
}
if (!this.properties[key]) {
this.properties[key] = {
default: value,
value: value,
enableCache: enableCache
};
}
return this;
};
Globals.prototype.getKeyValue = function (key) {
var property = this.properties[key];
if (property) {
if (typeof property.value === 'function') {
if (property.cachedValue) {
return property.cachedValue;
}
if (property.enableCache) {
property.cachedValue = property.value();
return property.cachedValue;
} else {
return property.value();
}
}
return property.value;
}
};
Globals.prototype.makeExport = function (key) {
return function (value) {
if (arguments.length === 0) {
return this.getKeyValue(key);
}
if (typeof value === 'undefined' || value === null) {
this.deleteKeyValue(key);
} else {
if (typeof value === 'function') {
this.setKeyValue(key, function () {
return value;
});
} else {
this.setKeyValue(key, value);
}
return value;
}
}.bind(this);
};
Globals.prototype.offKeyValue = function (key, handler) {
if (this.properties[key]) {
var handlers = this.eventHandlers[key];
if (handlers) {
var i = handlers.indexOf(handler);
handlers.splice(i, 1);
}
}
return this;
};
Globals.prototype.onKeyValue = function (key, handler) {
if (this.properties[key]) {
if (!this.eventHandlers[key]) {
this.eventHandlers[key] = [];
}
this.eventHandlers[key].push(handler);
}
return this;
};
Globals.prototype.deleteKeyValue = function (key) {
var property = this.properties[key];
if (property !== undefined) {
property.value = property.default;
property.cachedValue = undefined;
dispatch.call(this, key);
}
return this;
};
Globals.prototype.setKeyValue = function (key, value) {
if (!this.properties[key]) {
return this.define(key, value);
}
var property = this.properties[key];
property.value = value;
property.cachedValue = undefined;
dispatch.call(this, key);
return this;
};
Globals.prototype.reset = function () {
for (var key in this.properties) {
if (this.properties.hasOwnProperty(key)) {
this.properties[key].value = this.properties[key].default;
this.properties[key].cachedValue = undefined;
dispatch.call(this, key);
}
}
return this;
};
canReflect.assignSymbols(Globals.prototype, {
'can.getKeyValue': Globals.prototype.getKeyValue,
'can.setKeyValue': Globals.prototype.setKeyValue,
'can.deleteKeyValue': Globals.prototype.deleteKeyValue,
'can.onKeyValue': Globals.prototype.onKeyValue,
'can.offKeyValue': Globals.prototype.offKeyValue
});
module.exports = Globals;
}(function () {
return this;
}()));
});
25 changes: 25 additions & 0 deletions dist/amd/can-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*can-globals@0.2.5#can-globals*/
define([
'require',
'exports',
'module',
'./can-globals-instance',
'./global/global',
'./document/document',
'./location/location',
'./mutation-observer/mutation-observer',
'./is-browser-window/is-browser-window'
], function (require, exports, module) {
(function (global) {
'use strict';
var globals = require('./can-globals-instance');
require('./global/global');
require('./document/document');
require('./location/location');
require('./mutation-observer/mutation-observer');
require('./is-browser-window/is-browser-window');
module.exports = globals;
}(function () {
return this;
}()));
});
20 changes: 20 additions & 0 deletions dist/amd/document/document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*can-globals@0.2.5#document/document*/
define([
'require',
'exports',
'module',
'../global/global',
'../can-globals-instance'
], function (require, exports, module) {
(function (global) {
'use strict';
require('../global/global');
var globals = require('../can-globals-instance');
globals.define('document', function () {
return globals.getKeyValue('global').document;
});
module.exports = globals.makeExport('document');
}(function () {
return this;
}()));
});
18 changes: 18 additions & 0 deletions dist/amd/global/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*can-globals@0.2.5#global/global*/
define([
'require',
'exports',
'module',
'../can-globals-instance'
], function (require, exports, module) {
(function (global) {
'use strict';
var globals = require('../can-globals-instance');
globals.define('global', function () {
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : typeof process === 'object' && {}.toString.call(process) === '[object process]' ? global : window;
});
module.exports = globals.makeExport('global');
}(function () {
return this;
}()));
});
18 changes: 18 additions & 0 deletions dist/amd/is-browser-window/is-browser-window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*can-globals@0.2.5#is-browser-window/is-browser-window*/
define([
'require',
'exports',
'module',
'../can-globals-instance'
], function (require, exports, module) {
(function (global) {
'use strict';
var globals = require('../can-globals-instance');
globals.define('isBrowserWindow', function () {
return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof SimpleDOM === 'undefined';
});
module.exports = globals.makeExport('isBrowserWindow');
}(function () {
return this;
}()));
});
20 changes: 20 additions & 0 deletions dist/amd/location/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*can-globals@0.2.5#location/location*/
define([
'require',
'exports',
'module',
'../global/global',
'../can-globals-instance'
], function (require, exports, module) {
(function (global) {
'use strict';
require('../global/global');
var globals = require('../can-globals-instance');
globals.define('location', function () {
return globals.getKeyValue('global').location;
});
module.exports = globals.makeExport('location');
}(function () {
return this;
}()));
});
21 changes: 21 additions & 0 deletions dist/amd/mutation-observer/mutation-observer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*can-globals@0.2.5#mutation-observer/mutation-observer*/
define([
'require',
'exports',
'module',
'../global/global',
'../can-globals-instance'
], function (require, exports, module) {
(function (global) {
'use strict';
require('../global/global');
var globals = require('../can-globals-instance');
globals.define('MutationObserver', function () {
var GLOBAL = globals.getKeyValue('global');
return GLOBAL.MutationObserver || GLOBAL.WebKitMutationObserver || GLOBAL.MozMutationObserver;
});
module.exports = globals.makeExport('MutationObserver');
}(function () {
return this;
}()));
});
10 changes: 10 additions & 0 deletions dist/cjs/can-globals-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*can-globals@0.2.5#can-globals-instance*/
'use strict';
var namespace = require('can-namespace');
var Globals = require('./can-globals-proto.js');
var globals = new Globals();
if (namespace.globals) {
throw new Error('You can\'t have two versions of can-globals, check your dependencies');
} else {
module.exports = namespace.globals = globals;
}
Loading

0 comments on commit 38c89b5

Please sign in to comment.