Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all jQuery promises to native ES6 Promise (ref: $.Deferred(), $.when(), $.get() and $.post()) #308

Draft
wants to merge 56 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f2f7104
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
f67ed66
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
65c9399
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
ed7c43b
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
7603140
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
a8a62dd
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
42f826b
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
a1f9cb4
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
12c6258
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
4fded2e
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
acd3404
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
87c3a21
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
4d5e298
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
5c961cf
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
bf06032
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
de6424f
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
370c791
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
f98ceb1
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
7cfb0a3
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
76d1f69
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
dfbe30a
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
17c6476
Replace $.Deferred with Promise.resolve
volterra79 Jan 18, 2023
adb68c6
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
619b441
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
68f2b94
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
017f133
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
e5da2d5
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
c2f873e
Replace $.Deferred with new Promise
volterra79 Jan 18, 2023
5219444
Replace .fail (Jquery Deferred method) with .catch (Promise Method)
volterra79 Jan 18, 2023
5c74da0
Replace .catch .fail on $.get
volterra79 Jan 18, 2023
3534b33
Replace $.when jquery method with Promise.allSettled
volterra79 Jan 18, 2023
d1577eb
Replace .catch with .fail due of use of $.get jquery method
volterra79 Jan 18, 2023
ae0c0c6
Replace .catch with .fail due of use of $.ajax jquery method
volterra79 Jan 18, 2023
98a4d12
add a fallback for jQuery fail() and always() methods
Raruto Jan 19, 2023
f780905
add a fallback for native catch() and finall() methods
Raruto Jan 19, 2023
f658c6a
Replace .catch with .fail due of use of $.post jquery method
volterra79 Jan 19, 2023
977d9f6
Merge branch 'replace-jquery-Deferred-with-Promise' of https://github…
volterra79 Jan 19, 2023
839549a
Setter function return directly a value instead a promise as $.Deferr…
volterra79 Jan 19, 2023
c7cf200
Mispelling Defferred instead Deferred
volterra79 Jan 19, 2023
7b78192
Promise resolve has jus one parameter <value>. So need to wrap multi …
volterra79 Jan 19, 2023
cbd94bd
Replace $.get with XHR.get and $.post with XHR.post
volterra79 Jan 20, 2023
757e32f
Revert comment code used for internal development
volterra79 Jan 20, 2023
5af9b70
Set Object to params on XHR.get method
volterra79 Jan 20, 2023
54f04c8
Add _promise_methods Object to handle resolve and reject from externa…
volterra79 Jan 20, 2023
3873f2b
Chane .done method of return $.Deferred promise to .then Promise
volterra79 Jan 20, 2023
2508d4b
Replace $.when with Promise.all
volterra79 Jan 20, 2023
a733357
add a fallback for jQuery `resolve()` and `reject()` methods
Raruto Jan 24, 2023
dc36bc2
add deprecation warning for `$.Deferred::resolve()` and `$.Deferred::…
Raruto Jan 24, 2023
8aced3d
add deprecation notice for `$.Deferred::promise()` and `$.Deferred::d…
Raruto Jan 24, 2023
2b0da39
reduce deprecation warning verbosity
Raruto Jan 24, 2023
92959b8
add deprecation notice for `$.get()` and `$.post()`
Raruto Feb 3, 2023
419c113
Merge branch 'dev' into replace-jquery-Deferred-with-Promise
Raruto Jul 21, 2023
c535906
Merge branch 'dev' into replace-jquery-Deferred-with-Promise
Raruto Feb 15, 2024
e8ca08e
replace almost all jquery promises
Raruto Feb 16, 2024
2269a40
wrong method
Raruto Feb 19, 2024
f7f4ba3
Clean code
volterra79 Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"regenerator-runtime": "^0.13.9",
"shp-write": "^0.3.2",
"util-deprecate": "^1.0.2",
"vue": "2.6.12",
"vue-color": "^2.8.1",
"vue-cookie": "^1.1.4",
Expand Down
127 changes: 58 additions & 69 deletions src/app/core/editing/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,34 @@ proto._doGetFeaturesRequest = function(options={}) {

// get features from server method
proto._getFeatures = function(options={}) {
const d = $.Deferred();
const doRequest = this._doGetFeaturesRequest(options);
if (!doRequest) d.resolve();
else
this._layer.getFeatures(options)
.then(promise => {
promise.then(features => {
return new Promise((resolve, reject) => {
const doRequest = this._doGetFeaturesRequest(options);
if (!doRequest) resolve();
else
this._layer.getFeatures(options)
.then(features => {
this._addFeaturesFromServer(features);
this._allfeatures = !options.filter;
return d.resolve(features);
}).fail(err => d.reject(err))
})
.fail(err => d.reject(err));
return d.promise();
return resolve(features);
})
.catch(err => reject(err))
});
};

// method to revert (cancel) all changes in history and clean session
proto.revert = function() {
const d = $.Deferred();
const features = this._cloneFeatures(this._layer.readFeatures());
this._featuresstore.setFeatures(features);
d.resolve();
return d.promise();
return new Promise((resolve, reject) => {
const features = this._cloneFeatures(this._layer.readFeatures());
this._featuresstore.setFeatures(features);
resolve();
})
};

proto.rollback = function(changes=[]) {
const d = $.Deferred();
this._applyChanges(changes, true);
d.resolve();
return d.promise()
return new Promise((resolve, reject) => {
this._applyChanges(changes, true);
resolve();
})
};

proto.applyChangesToNewRelationsAfterCommit = function(relationsResponse) {
Expand Down Expand Up @@ -208,51 +206,42 @@ proto.getLockIds = function(){

// run after server apply changed to origin resource
proto.commit = function(commitItems) {
const d = $.Deferred();
// in case of relations bind to new feature
const relations = commitItems.add.length ? Object.keys(commitItems.relations).map(relationId => {
const layerRelation = this._layer.getRelations().getRelationByFatherChildren(this._layer.getId(), relationId);
const updates = commitItems.relations[relationId].update.map(relation => relation.id);
const add = commitItems.relations[relationId].add.map(relation => relation.id);
return {
[relationId]:{
ids: [...add, ...updates],
fatherField: layerRelation.getFatherField(),
childField: layerRelation.getChildField()
return new Promise((resolve, reject) => {
// in case of relations bind to new feature
const relations = commitItems.add.length ? Object.keys(commitItems.relations).map(relationId => {
const layerRelation = this._layer.getRelations().getRelationByFatherChildren(this._layer.getId(), relationId);
const updates = commitItems.relations[relationId].update.map(relation => relation.id);
const add = commitItems.relations[relationId].add.map(relation => relation.id);
return {
[relationId]:{
ids: [...add, ...updates],
fatherField: layerRelation.getFatherField(),
childField: layerRelation.getChildField()
}
}
}
}) : [];
this._layer.commit(commitItems)
.then(promise => {
promise
.then(response => {
this.applyCommitResponse(response, relations);
d.resolve(response);
})
.fail(err => d.reject(err))
})
.fail(err => d.reject(err));
return d.promise();
}) : [];
this._layer.commit(commitItems)
.then(response => {
this.applyCommitResponse(response, relations);
resolve(response);
})
.catch(err => reject(err))
})
};

//start editing function
proto.start = function(options={}) {
const d = $.Deferred();
// load features of layer based on filter type
this.getFeatures(options)
.then(promise => {
promise
.then(features => {
// the features are already inside featuresstore
d.resolve(features);
//if all ok set to started
this._started = true;
})
.fail(err => d.reject(err))

})
.fail(err => d.reject(err));
return d.promise()
return new Promise((resolve, reject) => {
// load features of layer based on filter type
this.getFeatures(options)
.then(features => {
// the features are already inside featuresstore
resolve(features);
//if all ok set to started
this._started = true;
})
.catch(err => reject(err))
})
};

//action to layer
Expand Down Expand Up @@ -283,14 +272,14 @@ proto.readEditingFeatures = function(){

// stop editor
proto.stop = function() {
const d = $.Deferred();
this._layer.unlock()
.then(response => {
this.clear();
d.resolve(response);
})
.fail(err => d.reject(err));
return d.promise();
return new Promise((resolve, reject) => {
this._layer.unlock()
.then(response => {
this.clear();
resolve(response);
})
.catch(err => reject(err));
})
};

//run save layer
Expand Down
50 changes: 25 additions & 25 deletions src/app/core/editing/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ const proto = History.prototype;

proto.add = function(uniqueId, items) {
//state object is an array of feature/features changed in a transaction
const d = $.Deferred();
// before insert an item into the history
// check if are at last state step (no redo was done)
// in this way avoid starge barch in the history
//If we are in the middle of undo, delete all changes in the histroy from the current "state"
// so i can create a new history
return new Promise((resolve, reject) => {
// before insert an item into the history
// check if are at last state step (no redo was done)
// in this way avoid starge barch in the history
//If we are in the middle of undo, delete all changes in the histroy from the current "state"
// so i can create a new history

if (this._current === null) {
this._states = [{
id: uniqueId,
items
}]
} else {
if (this._states.length && this._current < this.getLastState().id)
this._states = this._states.filter(state => state.id <= this._current);
this._states.push({
id: uniqueId,
items
});
}
if (this._current === null) {
this._states = [{
id: uniqueId,
items
}]
} else {
if (this._states.length && this._current < this.getLastState().id)
this._states = this._states.filter(state => state.id <= this._current);
this._states.push({
id: uniqueId,
items
});
}

this._current = uniqueId;
this._setState();
// return unique id key
// it can be used in save relation
d.resolve(uniqueId);
return d.promise();
this._current = uniqueId;
this._setState();
// return unique id key
// it can be used in save relation
resolve(uniqueId);
})
};

proto.getRelationStates = function(layerId, {clear=false}={}) {
Expand Down
Loading