Since there is no discussion forum for 5.x, I am posting it here.
Improved, this can also be applied to a 'Ext.data.Store' definition.
I modified 'Ext.data.proxy.Server' for 'extraParams' expansion from function to object.
This has just been tested for my initial use.
Data Proxy with Extra Params as Global Function definition
Instead of having to supply extraParams with each CRUD process I modified the source to allow extraParams as a global function definition which can dynamically change over time. This should reduce coding over time and human error.
As of now one must always define extraParams in the CRUD call to be dynamic.
Code:
MyModelSuper.load(id, {
extraParams: MyApp.GlobalFunction()
});
Improved, this can also be applied to a 'Ext.data.Store' definition.
Code:
Ext.define('MyModelBase', {
extend: 'Ext.data.Model',
extraParams: MyApp.GlobalFunction
});
I modified 'Ext.data.proxy.Server' for 'extraParams' expansion from function to object.
Code:
buildRequest: function(operation) {
var me = this,
initialParams = Ext.apply({}, operation.getParams()),
extraParams = me.expandParams(me.getExtraParams() || {}), // allow for extraParams to be an object or function
// Clone params right now so that they can be mutated at any point further down the call stack
params = Ext.applyIf(initialParams, extraParams),
request,
operationId,
idParam;
...
...
...
},
// expand source into an object of primitives
expandParams: function(source) {
var params = {},
funcFound = true,
property,
result;
// apply source function results or source object
if (Ext.isFunction(source)) {
params = Ext.applyIf(params, source() || {});
} else {
params = Ext.applyIf(params, source);
}
// run all function properties that might exist in a tree structure
while (funcFound) {
funcFound = false;
for (property in params) {
if (Ext.isFunction(params[property])) {
funcFound = true;
result = params[property]();
// apply result object or result primitive
if (Ext.isObject(result)) {
params = Ext.applyIf(params, result);
} else {
params[property] = result;
}
}
}
}
return params;
},
...
This has just been tested for my initial use.
Data Proxy with Extra Params as Global Function definition
Aucun commentaire:
Enregistrer un commentaire