Skip to content

Commit

Permalink
A few small little updates...
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package-lock.json
.DS_Store
.vscode/
dist/
node_modules/
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ npm install
node build.js
```

## Dependencies
* [UIkit](https://github.com/uikit/uikit) → Used for rendering the process UI

## API
## Process

Expand Down Expand Up @@ -57,6 +60,11 @@ node build.js
```
- updates the title in the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)

```js
getStatus()
```
- gets the current status of this process


## ProcessQueue

Expand Down Expand Up @@ -95,3 +103,7 @@ node build.js
```
- updates the title in the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)

```js
getStatus()
```
- gets the current status of this queue
228 changes: 228 additions & 0 deletions dist/process.js
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'
});
1 change: 1 addition & 0 deletions dist/process.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions package.json
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"
}
}
4 changes: 4 additions & 0 deletions src/Process.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ class Process {
appendToElement(element){
element.appendChild(this._.component.getElement());
}

getStatus(){
return this._.status;
}
}
4 changes: 4 additions & 0 deletions src/ProcessQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ class ProcessQueue {
catch(reject){
this._.promise.get().catch(reject);
}

getStatus(){
return this._.status;
}
}
6 changes: 3 additions & 3 deletions src/ProcessStatus.js
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'
});

0 comments on commit c32c31a

Please sign in to comment.