Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
feat(configure eslint) (#6)
Browse files Browse the repository at this point in the history
* updated packages

* installed eslint

* fixed indent

* removed semicolons

* removed semicolons

* removed unused argument
  • Loading branch information
ProticM committed Feb 5, 2019
1 parent 211a14e commit ee3060f
Show file tree
Hide file tree
Showing 21 changed files with 2,995 additions and 2,666 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
947 changes: 623 additions & 324 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"@babel/preset-env": "^7.2.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"eslint": "^5.12.0",
"jest": "^23.6.0",
"lerna": "^3.8.0",
"rimraf": "^2.6.2",
"lerna": "^3.10.5",
"rimraf": "^2.6.3",
"rollup": "^0.67.4",
"rollup-plugin-babel": "^4.1.0",
"rollup-plugin-babel": "^4.3.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0",
"uglify-js": "^3.4.9"
Expand Down
276 changes: 138 additions & 138 deletions packages/core/src/asset-types/base.js
Original file line number Diff line number Diff line change
@@ -1,143 +1,143 @@
import pz from '../core';

class base {
init() { };
destroy() {
let idx = pz.application.instances.indexOf(this);
if (idx != -1) {
pz.application.instances.splice(idx, 1);
};
};
applyMixins() {
let me = this;
pz.forEach(this.mixins, function (m) {
let mixin = pz.isMixin(m) ? m : pz.getDefinitionOf(m);
let cleanMixin = pz.assignTo({}, mixin);
delete cleanMixin.ownerType;
delete cleanMixin.type;
pz.assignTo(me, cleanMixin, false);
});
};
setRequiredInstances() {
let isModularEnv = pz.isModularEnv();
let requireDefined = !pz.isEmpty(this.require) &&
pz.isArray(this.require);
if (isModularEnv || !requireDefined) {
return;
};
pz.forEach(this.require, function (requiredItemType) {
let instance = pz.getInstanceOf(requiredItemType)
let requiredItem = pz.isEmpty(instance) ?
pz.getDefinitionOf(requiredItemType) : instance;
let camelCaseName = pz.str.camelize(requiredItemType);
if (!pz.isEmpty(requiredItem) && pz.isEmpty(this[camelCaseName])) {
this[camelCaseName] = !pz.isFunction(requiredItem) ? requiredItem :
pz.create(requiredItemType);
};
}, this);
};
static extend(props) {
// TODO: Inherit statics
let properties = (pz.toObject(props) || {}), parentClass, returnVal;
if(pz.isEmpty(properties.type)) {
throw new Error("It seems that you are trying to create an object without a type definition. Example invocation: myDefinition.extend({ type: 'my-type' // other configs });");
};
parentClass = this;
returnVal = (function (_parentClass, _properties) {
let _hasCustomConstructor = _properties && _properties.constructor
&& _properties.constructor !== {}.constructor;
let propertyNames = Object.keys(_properties);
let propertiesReduced = propertyNames.reduce(function (acc, key) {
let isFunction = pz.isFunction(_properties[key]);
acc[isFunction ? 'fnKeys' : 'attrKeys'].push(key);
return acc;
}, { fnKeys: [], attrKeys: [] });
let pz_type = function () { // child class
let me = this, result;
pz.forEach(propertiesReduced.attrKeys, function (key) { // apply properties (strings, ints, arrays, objects...etc) to the object instance
if (!me.hasOwnProperty(key) && !pz.isEmpty(_properties[key], true)) {
let isArray = pz.isArray(_properties[key]);
let isObject = pz.isObject(_properties[key]);
me[key] = (isArray ? pz.deepClone(_properties[key]) : (isObject ? pz.assignTo({}, _properties[key]) : _properties[key]));
};
});
this.ownerType = this.ownerType || _parentClass.$type || 'base';
this.base = _hasCustomConstructor ? _parentClass : null;
result = _hasCustomConstructor ? _properties.constructor.apply(this, arguments)
: _parentClass.apply(this, arguments);
this.base = null;
return result || me;
};
pz_type.prototype = Object.create(_parentClass.prototype);
pz_type.prototype.constructor = pz_type;
pz.forEach(propertiesReduced.fnKeys, function (key) {
pz_type.prototype[key] = key == 'constructor' ? pz_type.prototype.constructor : (function (name, fn, base) { // share the functions between instances via prototype
return function () {
let tmp = this.base;
let addSuperCallWrapper = !pz.isEmpty(base[name]) && pz.isFunction(base[name]);
this.base = addSuperCallWrapper ? base[name] : function () {
throw new Error('Method named: [' + name + '] was not found on type: [' + this.ownerType + ']');
};
let result = fn.apply(this, arguments);
this.base = tmp;
return result;
};
})(key, _properties[key], _parentClass.prototype);
});
pz_type.extend = _parentClass.extend;
pz_type.create = _parentClass.create;
pz_type.$isPz = true;
pz_type.$type = _properties.type;
return pz_type;
})(parentClass, properties);
properties = null;
parentClass = null;
return returnVal;
};
static create(config) {
let params, instance;
if(!pz.isEmpty(config)) {
params = pz.assignTo({}, config, false);
delete params.type;
delete config.type;
instance = new this(params);
pz.assignTo(instance, config, false);
} else {
instance = new this();
};

instance.id = pz.guid();
instance.autoLoad = !pz.isEmpty(this.autoLoad) ? this.autoLoad : instance.autoLoad;
delete this.autoLoad;
instance.setRequiredInstances();

if (pz.isComponent(instance) || pz.isClass(instance)) {
instance.applyMixins();

if (instance.autoLoad) {
instance.load();
};
};
pz.application.instances.push(instance);

return instance;
}
};
init() { }
destroy() {
let idx = pz.application.instances.indexOf(this);
if (idx != -1) {
pz.application.instances.splice(idx, 1);
}
}
applyMixins() {
let me = this;
pz.forEach(this.mixins, function (m) {
let mixin = pz.isMixin(m) ? m : pz.getDefinitionOf(m);
let cleanMixin = pz.assignTo({}, mixin);
delete cleanMixin.ownerType;
delete cleanMixin.type;
pz.assignTo(me, cleanMixin, false);
});
}
setRequiredInstances() {
let isModularEnv = pz.isModularEnv();
let requireDefined = !pz.isEmpty(this.require) &&
pz.isArray(this.require);

if (isModularEnv || !requireDefined) {
return;
}

pz.forEach(this.require, function (requiredItemType) {
let instance = pz.getInstanceOf(requiredItemType);
let requiredItem = pz.isEmpty(instance) ?
pz.getDefinitionOf(requiredItemType) : instance;
let camelCaseName = pz.str.camelize(requiredItemType);

if (!pz.isEmpty(requiredItem) && pz.isEmpty(this[camelCaseName])) {
this[camelCaseName] = !pz.isFunction(requiredItem) ? requiredItem :
pz.create(requiredItemType);
}
}, this);
}
static extend(props) {
// TODO: Inherit statics

let properties = (pz.toObject(props) || {}), parentClass, returnVal;
if(pz.isEmpty(properties.type)) {
throw new Error('It seems that you are trying to create an object without a type definition. Example invocation: myDefinition.extend({ type: "my-type" // other configs });');
}
parentClass = this;

returnVal = (function (_parentClass, _properties) {
let _hasCustomConstructor = _properties && _properties.constructor
&& _properties.constructor !== {}.constructor;
let propertyNames = Object.keys(_properties);
let propertiesReduced = propertyNames.reduce(function (acc, key) {
let isFunction = pz.isFunction(_properties[key]);
acc[isFunction ? 'fnKeys' : 'attrKeys'].push(key);
return acc;
}, { fnKeys: [], attrKeys: [] });

let pz_type = function () { // child class
let me = this, result;
pz.forEach(propertiesReduced.attrKeys, function (key) { // apply properties (strings, ints, arrays, objects...etc) to the object instance
if (!me.hasOwnProperty(key) && !pz.isEmpty(_properties[key], true)) {
let isArray = pz.isArray(_properties[key]);
let isObject = pz.isObject(_properties[key]);

me[key] = (isArray ? pz.deepClone(_properties[key]) : (isObject ? pz.assignTo({}, _properties[key]) : _properties[key]));
}
});
this.ownerType = this.ownerType || _parentClass.$type || 'base';
this.base = _hasCustomConstructor ? _parentClass : null;
result = _hasCustomConstructor ? _properties.constructor.apply(this, arguments)
: _parentClass.apply(this, arguments);
this.base = null;
return result || me;
};

pz_type.prototype = Object.create(_parentClass.prototype);
pz_type.prototype.constructor = pz_type;

pz.forEach(propertiesReduced.fnKeys, function (key) {
pz_type.prototype[key] = key == 'constructor' ? pz_type.prototype.constructor : (function (name, fn, base) { // share the functions between instances via prototype
return function () {
let tmp = this.base;
let addSuperCallWrapper = !pz.isEmpty(base[name]) && pz.isFunction(base[name]);
this.base = addSuperCallWrapper ? base[name] : function () {
throw new Error('Method named: [' + name + '] was not found on type: [' + this.ownerType + ']');
};
let result = fn.apply(this, arguments);
this.base = tmp;
return result;
};
})(key, _properties[key], _parentClass.prototype);
});

pz_type.extend = _parentClass.extend;
pz_type.create = _parentClass.create;
pz_type.$isPz = true;
pz_type.$type = _properties.type;
return pz_type;

})(parentClass, properties);

properties = null;
parentClass = null;

return returnVal;
}
static create(config) {
let params, instance;

if(!pz.isEmpty(config)) {
params = pz.assignTo({}, config, false);
delete params.type;
delete config.type;
instance = new this(params);
pz.assignTo(instance, config, false);
} else {
instance = new this();
}

instance.id = pz.guid();
instance.autoLoad = !pz.isEmpty(this.autoLoad) ? this.autoLoad : instance.autoLoad;
delete this.autoLoad;
instance.setRequiredInstances();

if (pz.isComponent(instance) || pz.isClass(instance)) {
instance.applyMixins();

if (instance.autoLoad) {
instance.load();
}
}
pz.application.instances.push(instance);

return instance;
}
}

export default base;
4 changes: 2 additions & 2 deletions packages/core/src/asset-types/class.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cls = {
type: 'class'
// common
type: 'class'
// common
};

export default cls;
Loading

0 comments on commit ee3060f

Please sign in to comment.