-
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.
ADDED: dist folder in the repository ADDED: package-lock.json because stackoverflow said I was supposed to :) ADDED: methods getStatus in both Process and ProcessQueue class REMOVED: unwnated npm dependencies
- Loading branch information
Abhay Jatin Doshi
committed
Feb 16, 2019
1 parent
0871be9
commit c32c31a
Showing
9 changed files
with
300 additions
and
9 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
package-lock.json | ||
.DS_Store | ||
.vscode/ | ||
dist/ | ||
node_modules/ |
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,228 @@ | ||
class Process { | ||
constructor(invoker,title){ | ||
this._ = {}; | ||
if(invoker instanceof Function){ | ||
this._.promise = new Promise(invoker); | ||
} else if (invoker instanceof Promise){ | ||
this._.promise = invoker; | ||
} else { | ||
throw new TypeError('Invalid invoker passed for Process constructor'); | ||
} | ||
|
||
this._.component = (function(){ | ||
var div = document.createElement('div'); | ||
|
||
var statusIcon = document.createElement('span'); | ||
statusIcon.setAttribute('uk-spinner','ratio: .7'); | ||
div.appendChild(statusIcon); | ||
|
||
var processTitle = document.createElement('span'); | ||
if(title){ | ||
processTitle.innerText = ' '+title; | ||
} | ||
div.appendChild(processTitle); | ||
|
||
return { | ||
success: function(){ | ||
statusIcon.removeAttribute('uk-spinner'); | ||
statusIcon.classList.remove('uk-spinner'); | ||
statusIcon.setAttribute('uk-icon','icon: check'); | ||
div.classList.add('uk-text-success'); | ||
}, | ||
failure: function(){ | ||
statusIcon.removeAttribute('uk-spinner'); | ||
statusIcon.classList.remove('uk-spinner'); | ||
statusIcon.setAttribute('uk-icon','icon: close'); | ||
div.classList.add('uk-text-danger'); | ||
}, | ||
updateTitle: function(title){ | ||
processTitle.innerText = ' '+title | ||
}, | ||
getElement: function(){ | ||
return div; | ||
} | ||
}; | ||
})(); | ||
|
||
var parent = this._; | ||
this._.status = ProcessStatus.INPROGRESS; | ||
this._.promise.then(function(){ | ||
parent.status = ProcessStatus.SUCCESS; | ||
parent.component.success(); | ||
},function(){ | ||
parent.status = ProcessStatus.FAILED; | ||
parent.component.failure(); | ||
}); | ||
|
||
} | ||
|
||
updateTitle(title){ | ||
this._.component.updateTitle(title); | ||
} | ||
|
||
then(resolve, reject){ | ||
this._.promise.then(resolve, reject); | ||
} | ||
|
||
catch(reject){ | ||
this._.promise.catch(reject); | ||
} | ||
|
||
appendToElement(element){ | ||
element.appendChild(this._.component.getElement()); | ||
} | ||
|
||
getStatus(){ | ||
return this._.status; | ||
} | ||
} | ||
class ProcessQueue { | ||
constructor(title){ | ||
this._ = {}; | ||
|
||
this._.component = (function(){ | ||
var div = document.createElement('div'); | ||
|
||
var subDiv = document.createElement('div'); | ||
div.appendChild(subDiv); | ||
|
||
var statusIcon = document.createElement('span'); | ||
statusIcon.setAttribute('uk-spinner','ratio: .7'); | ||
subDiv.appendChild(statusIcon); | ||
|
||
var processTitle = document.createElement('span'); | ||
if(title){ | ||
processTitle.innerText = ' '+title; | ||
} | ||
subDiv.appendChild(processTitle); | ||
|
||
var processElements = document.createElement('div'); | ||
processElements.classList.add('uk-margin-medium-left'); | ||
div.appendChild(processElements); | ||
|
||
return { | ||
success: function(){ | ||
statusIcon.removeAttribute('uk-spinner'); | ||
statusIcon.classList.remove('uk-spinner'); | ||
statusIcon.setAttribute('uk-icon','icon: check'); | ||
subDiv.classList.add('uk-text-success'); | ||
}, | ||
failure: function(){ | ||
statusIcon.removeAttribute('uk-spinner'); | ||
statusIcon.classList.remove('uk-spinner'); | ||
statusIcon.setAttribute('uk-icon','icon: close'); | ||
subDiv.classList.add('uk-text-danger'); | ||
}, | ||
updateTitle: function(){ | ||
processTitle.innerText = ' '+title | ||
}, | ||
getProcessElement: function(){ | ||
return processElements; | ||
}, | ||
getElement: function(){ | ||
return div; | ||
} | ||
}; | ||
|
||
})(); | ||
|
||
var parentData = this._; | ||
this._.status = ProcessStatus.INPROGRESS; | ||
this._.promise = (function(){ | ||
var resolve; | ||
var reject; | ||
var promise = new Promise(function(res,rej){ | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
|
||
return { | ||
get: function(){ | ||
return promise; | ||
}, | ||
resolve: function(){ | ||
resolve.apply(undefined,arguments); | ||
}, | ||
reject: function(){ | ||
reject.apply(undefined,arguments); | ||
} | ||
}; | ||
})(); | ||
|
||
this._.processList = (function(){ | ||
var processList = []; | ||
var resolvedCount = 0; | ||
var successCount = 0; | ||
var failureCount = 0; | ||
var parent = parentData; | ||
|
||
var successCallback = function(){ | ||
resolvedCount++; | ||
successCount++; | ||
if(resolvedCount == processList.length){ | ||
if(failureCount == 0){ | ||
parent.status = ProcessStatus.SUCCESS; | ||
parent.component.success(); | ||
parent.promise.resolve(); | ||
} else { | ||
parent.status = ProcessStatus.FAILED; | ||
parent.component.failure(); | ||
parent.promise.reject(); | ||
} | ||
} | ||
} | ||
|
||
var failureCallback = function(){ | ||
resolvedCount++; | ||
failureCount++; | ||
if(resolvedCount == processList.length){ | ||
parent.status = ProcessStatus.FAILED; | ||
parent.component.failure(); | ||
parent.promise.reject(); | ||
} | ||
} | ||
|
||
return { | ||
push : function(process){ | ||
if(process instanceof Process || process instanceof ProcessQueue){ | ||
process.then(successCallback, failureCallback); | ||
} else { | ||
throw new TypeError('Invalid process type pushed to the queue'); | ||
} | ||
processList.push(process); | ||
process.appendToElement(parent.component.getProcessElement()); | ||
} | ||
} | ||
})(); | ||
|
||
} | ||
|
||
appendToElement(element){ | ||
element.appendChild(this._.component.getElement()); | ||
} | ||
|
||
push(process){ | ||
this._.processList.push(process); | ||
} | ||
|
||
updateTitle(title){ | ||
this._.component.updateTitle(title); | ||
} | ||
|
||
then(resolve, reject){ | ||
this._.promise.get().then(resolve, reject); | ||
} | ||
|
||
catch(reject){ | ||
this._.promise.get().catch(reject); | ||
} | ||
|
||
getStatus(){ | ||
return this._.status; | ||
} | ||
} | ||
ProcessStatus = Object.freeze({ | ||
'INPROGRESS':'INPROGRESS', | ||
'SUCCESS':'SUCCESS', | ||
'FAILED':'FAILED' | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,23 @@ | ||
{ | ||
"name": "process-manager", | ||
"version": "0.1", | ||
"build": "build.js", | ||
"version": "1.0.0", | ||
"description": "This manager helps you to handle multiple promises effortlessly. This library will handle processes and its sub processes and its sub process and so on...", | ||
"main": "build.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/abhayjatindoshi/process-manager.git" | ||
}, | ||
"author": "Abhay Jatin Doshi", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/abhayjatindoshi/process-manager/issues" | ||
}, | ||
"homepage": "https://github.com/abhayjatindoshi/process-manager#readme", | ||
"dependencies": { | ||
"babel-core": "^6.26.3", | ||
"fs": "0.0.1-security", | ||
"uglify": "^0.1.5", | ||
"uglify-es": "^3.3.9" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
ProcessStatus = Object.freeze({ | ||
'INPROGRESS':0, | ||
'SUCCESS':1, | ||
'FAILED':2 | ||
'INPROGRESS':'INPROGRESS', | ||
'SUCCESS':'SUCCESS', | ||
'FAILED':'FAILED' | ||
}); |