After port all our code from the old javascript library to the new one we have some suggestions that could make easier the use of the library.
1. Add a function to map a SFSArray to an javascript array of one type
In many cases a SFSArray contains only SFSObjects or SFSArrays and usually we map then to other structures/classes. Now with the current implementation we do something like this:
Code: Select all
parseArray(dataArray) {
const result = [];
if (dataArray != null) {
for (let i = 0; i < dataArray.size(); i++) {
result.push(new Item(dataArray.getSFSObject(i)));
}
}
return result;
}
It would be nice if the library provides functions like SFSArray.map(type: SFSDataType) that simply returns a javascript array with all the objects mapped as the SFSDataType specified. Then we can do things like
Code: Select all
const mappedObjects = dataArray.map(SFSDataType.SFS_ARRAY).map(mapingFunction);
2. Add the function 'contains' to SFSArray and SFSObject
Now to know if an object or an array contains an element we have to do a 'get' and check if it's not null. For an SFSObject this works perfect but, with the SFSArray, if we get a position that can be, for example, null or String we must use the 'get' without type before and then check if it's null. if we don't do that we will get an exception.
Code: Select all
//Bad code
const myString = sfsArray.getUtfString(0); //If this is null it would fail
if (myString) console.log(myString)
Code: Select all
//Good code
if (sfsArray.get(0)) {
myString = sfsArray.getUtfString(0);
console.log(myString)
}
The problem is that the documentation don't let clear that sfsArray.getUtfString(0) would throw an exception with null. it would be nice if the SFSArray and the SFSObject provides the function 'contains' that returns a boolean to make the code more clear and avoid future mistakes.
3. Make the method fromSFSArray public in all your objects like SFSRoom, SFSUser, ...
In all the other clients we can user the method fromSFSArray to create an SFSRoom object from the SFSArray produced by the function toSFSArray on the server side.
We have been using this for some special functionalities of the moderators, and now in the new library this method is private. We know that we don't have to create rooms, we only use it because it come in handy to send the information of the rooms in some special cases and this wasn't a problem until now.
4. Add to SFSobject and SFSArray the possibility to get the long values as plain string or HEX
With the number limitation on javascript the long java numbers can be a problem but in the cases when we need the number it would be nice (and i don't now if possible) that the SFSArray and the SFSObject contains the functions getLongAsString getLongAsHEX. For example:
Code: Select all
veryLongNumber = sfsObject.getLong('veryLongNumber'); //Show a log warning
console.log(veryLongNumber); //NaN
veryLongNumber = sfsObject.getLongString('veryLongNumber');
console.log(veryLongNumber); //'10201670634517191'
veryLongNumber = sfsObject.getLongHEX('veryLongNumber');
console.log(veryLongNumber); //'243E5D8A4932C7'
5. Provide a d.ts of your lib
https://www.typescriptlang.org/docs/han ... ction.html
With the d.ts most of IDE's autocomplete the code of your lib simplifying the development and also allows to use your lib in a TypeScript environments.
We attach the one that we use as an example.
https://drive.google.com/open?id=0B5Pvd ... 3FYS3JjWTg
That's it, most of the suggestions can be implemented on our end with prototypes and so on but we think that can make the live easier to any one who starts using the library.
I hope that the points are well explained.
Regards and thank you for your time.