gengojs-default-api
Advanced tools
Comparing version 0.0.1-beta.5 to 0.0.1-beta.6
38
index.js
@@ -29,8 +29,7 @@ 'use strict'; | ||
var API = (function () { | ||
function API(object, _this) { | ||
function API(_this) { | ||
_classCallCheck(this, API); | ||
this.options = _this.options; | ||
this.object = object; | ||
this.apply(_this); | ||
this.context = _this; | ||
} | ||
@@ -42,5 +41,6 @@ | ||
/* Sets the API*/ | ||
value: function set(_this) { | ||
value: function set() { | ||
var _this2 = this; | ||
var _this = this.context; | ||
var i18n = function i18n() {}; | ||
@@ -260,4 +260,3 @@ var l10n = function l10n() {}; | ||
}; | ||
this.api = { | ||
return { | ||
i18n: i18n, | ||
@@ -268,7 +267,7 @@ l10n: l10n | ||
}, { | ||
key: 'api', | ||
key: 'get', | ||
/* Returns the Applied API */ | ||
value: function api() { | ||
return this.object; | ||
/* Get the API */ | ||
value: function get() { | ||
return this.apply({}); | ||
} | ||
@@ -279,9 +278,10 @@ }, { | ||
/* Private: Applies the API to any object */ | ||
value: function apply(_this) { | ||
_import2['default'].forEach(_this.set(_this), function (item, key) { | ||
value: function apply(object) { | ||
var _this = this.context; | ||
_import2['default'].forEach(this.set(), function (item, key) { | ||
switch (key) { | ||
case 'i18n': | ||
_import2['default'].forOwn(item, function (api, subkey) { | ||
if (!this.object[subkey]) { | ||
if (subkey === this.options.api.global) this.object[subkey] = api.bind(_this);else this.object[this.options.api.global][subkey] = api.bind(_this); | ||
if (!object[subkey]) { | ||
if (subkey === this.options.api.global) object[subkey] = api.bind(_this);else object[this.options.api.global][subkey] = api.bind(_this); | ||
} | ||
@@ -292,4 +292,4 @@ }, this); | ||
_import2['default'].forOwn(item, function (api, subkey) { | ||
if (!this.object[subkey]) { | ||
if (subkey === this.options.api.localize) this.object[subkey] = api.bind(_this); | ||
if (!object[subkey]) { | ||
if (subkey === this.options.api.localize) object[subkey] = api.bind(_this); | ||
} | ||
@@ -300,3 +300,4 @@ }, this); | ||
}, this); | ||
debug('API exists:', _import2['default'].has(this.object, this.options.api.global) && _import2['default'].has(this.object, this.options.api.localize)); | ||
debug('API exists:', _import2['default'].has(object, this.options.api.global) && _import2['default'].has(object, this.options.api.localize)); | ||
return object; | ||
} | ||
@@ -313,3 +314,4 @@ }]); | ||
var object = arguments[0] || arguments[1] || {}; | ||
this.api = new API(object, this); | ||
debug('object exists:', !!object); | ||
this.api = new API(this).apply(object); | ||
}, | ||
@@ -316,0 +318,0 @@ 'package': _import2['default'].merge({ |
@@ -7,9 +7,9 @@ import cldr from 'cldr'; | ||
class API { | ||
constructor(object, _this) { | ||
constructor(_this) { | ||
this.options = _this.options; | ||
this.object = object; | ||
this.apply(_this); | ||
this.context = _this; | ||
} | ||
/* Sets the API*/ | ||
set(_this) { | ||
set() { | ||
var _this = this.context; | ||
var i18n = function() {}; | ||
@@ -224,4 +224,3 @@ var l10n = function() {}; | ||
}; | ||
this.api = { | ||
return { | ||
i18n: i18n, | ||
@@ -231,17 +230,18 @@ l10n: l10n | ||
} | ||
/* Returns the Applied API */ | ||
api() { | ||
return this.object; | ||
/* Get the API */ | ||
get() { | ||
return this.apply({}); | ||
} | ||
/* Private: Applies the API to any object */ | ||
apply(_this) { | ||
_.forEach(_this.set(_this), function(item, key) { | ||
apply(object) { | ||
var _this = this.context; | ||
_.forEach(this.set(), function(item, key) { | ||
switch (key) { | ||
case 'i18n': | ||
_.forOwn(item, function(api, subkey) { | ||
if (!this.object[subkey]) { | ||
if (!object[subkey]) { | ||
if (subkey === this.options.api.global) | ||
this.object[subkey] = api.bind(_this); | ||
object[subkey] = api.bind(_this); | ||
else | ||
this.object[this.options.api.global][subkey] = api.bind(_this); | ||
object[this.options.api.global][subkey] = api.bind(_this); | ||
} | ||
@@ -252,5 +252,5 @@ }, this); | ||
_.forOwn(item, function(api, subkey) { | ||
if (!this.object[subkey]) { | ||
if (!object[subkey]) { | ||
if (subkey === this.options.api.localize) | ||
this.object[subkey] = api.bind(_this); | ||
object[subkey] = api.bind(_this); | ||
} | ||
@@ -262,4 +262,5 @@ }, this); | ||
debug('API exists:', | ||
_.has(this.object, this.options.api.global) && | ||
_.has(this.object, this.options.api.localize)); | ||
_.has(object, this.options.api.global) && | ||
_.has(object, this.options.api.localize)); | ||
return object; | ||
} | ||
@@ -274,3 +275,4 @@ } | ||
var object = arguments[0] || arguments[1] || {}; | ||
this.api = new API(object, this); | ||
debug('object exists:', !!object); | ||
this.api = new API(this).apply(object); | ||
}, | ||
@@ -277,0 +279,0 @@ package: _.merge({ |
{ | ||
"name": "gengojs-default-api", | ||
"version": "0.0.1-beta.5", | ||
"version": "0.0.1-beta.6", | ||
"description": "The default router plugin for gengojs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30125
602