-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,16 @@ | |
"name": "vuex-toolkit", | ||
"version": "0.0.1", | ||
"description": "Vuex Toolkit. An alternative API for Vuex.", | ||
"main": "index.ts", | ||
"main": "src/index.ts", | ||
"dependencies": { | ||
"lodash": "^4.17.15" | ||
}, | ||
"peerDependencies": { | ||
"vuex": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash": "^4.14.151" | ||
}, | ||
"repository": "[email protected]:banderror/vuex-toolkit.git", | ||
"author": "Georgii (Egor) Gorbachev <[email protected]>", | ||
"license": "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
/** | ||
* Returns an array with the names of the inherited enumerable properties of obj. | ||
*/ | ||
function getEnumerableInheritedPropertyNames(obj) { | ||
const result: any[] = []; | ||
for (const propName in obj) { // eslint-disable-line no-restricted-syntax, guard-for-in | ||
result.push(propName); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Returns an array with the names of the inherited properties of obj. | ||
*/ | ||
function getAllInheritedPropertyNames(obj) { | ||
if ((typeof obj) !== 'object') { // null is not a problem | ||
throw new Error('Only objects are allowed'); | ||
} | ||
|
||
const props = {}; | ||
|
||
while (obj) { | ||
const proto = Object.getPrototypeOf(obj); | ||
|
||
Object.getOwnPropertyNames(obj).forEach(p => { | ||
props[p] = true; | ||
}); | ||
obj = proto; // eslint-disable-line no-param-reassign | ||
} | ||
|
||
return Object.getOwnPropertyNames(props); | ||
} | ||
|
||
export class Binder { | ||
public static bindAllMethods(instance, cls?: Function) { | ||
const methods = this.getAllMethods(instance, cls); | ||
methods.forEach(mtd => { | ||
// eslint-disable-next-line no-param-reassign | ||
instance[mtd] = instance[mtd].bind(instance); | ||
}); | ||
} | ||
|
||
public static getAllMethods(instance, cls?: Function) { | ||
const prototype = Object.getPrototypeOf(instance); | ||
const ctor = cls || prototype.constructor; | ||
|
||
return getAllInheritedPropertyNames(instance) | ||
.filter(name => { | ||
const method = instance[name]; | ||
return method instanceof Function && method !== ctor; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Check for plain object. | ||
* | ||
* @param {Mixed} val | ||
* @return {Boolean} | ||
*/ | ||
export function isObject(val) { | ||
return val.constructor === Object; | ||
} | ||
|
||
/** | ||
* Check if `obj` is a promise. | ||
* | ||
* @param {Object} obj | ||
* @return {Boolean} | ||
*/ | ||
export function isPromise(obj) { | ||
// eslint-disable-next-line eqeqeq | ||
return typeof obj.then == 'function'; | ||
} | ||
|
||
/** | ||
* Check if `obj` is a generator. | ||
* | ||
* @param {Mixed} obj | ||
* @return {Boolean} | ||
*/ | ||
export function isGenerator(obj) { | ||
// eslint-disable-next-line eqeqeq | ||
return typeof obj.next == 'function' && typeof obj.throw == 'function'; | ||
} | ||
|
||
/** | ||
* Check if `obj` is a generator function. | ||
* | ||
* @param {Mixed} obj | ||
* @return {Boolean} | ||
*/ | ||
export function isGeneratorFunction(obj) { | ||
const { constructor } = obj; | ||
if (!constructor) return false; | ||
if (constructor.name === 'GeneratorFunction' || constructor.displayName === 'GeneratorFunction') return true; | ||
return isGenerator(constructor.prototype); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/lodash@^4.14.151": | ||
version "4.14.151" | ||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.151.tgz#7d58cac32bedb0ec37cb7f99094a167d6176c9d5" | ||
integrity sha512-Zst90IcBX5wnwSu7CAS0vvJkTjTELY4ssKbHiTnGcJgi170uiS8yQDdc3v6S77bRqYQIN1App5a1Pc2lceE5/g== | ||
|
||
lodash@^4.17.15: | ||
version "4.17.15" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" | ||
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== | ||
|
||
[email protected]: | ||
version "3.4.0" | ||
resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.4.0.tgz#20cc086062d750769fce1febb34e7fceeaebde45" | ||
integrity sha512-ajtqwEW/QhnrBZQsZxCLHThZZaa+Db45c92Asf46ZDXu6uHXgbfVuBaJ4gzD2r4UX0oMJHstFwd2r2HM4l8umg== |