Jump to content
warleyalex

mORMot with SMS

Recommended Posts

Smart Mobile Studio 3.1 with mORMot

Quote

Jarto: How did you solve the problem with synchronous http?

Nowadays, the synchronous methods are deprecated is most modern browsers, that "false" makes the request synchronous (i.g. request.open('GET', '/bar/foo.txt', false)), besides the message it works.

Note: Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), Blink 39.0, and Edge 13, synchronous requests on the main thread have been deprecated due to the negative effects to the user experience. Anyway, both synchronous and asynchronous methods are available, depending on use case. For instance, you can invoke a method to calculate both in syn or async ways. The synchronous, are methods starting with underscore _*() methods will block the browser execution, so won't be appropriate for long process - on error, they may raise EServiceException. It could be useful in order to interact in background with the server or the preload some content. You shouldn't use sync methods in the future, because it's deprecated. They work but shouldn't be there. I don't pretty sure, but I think the mORMot authentication scheme uses synchronous method for the handshaking process.

Quote

Roberto I'm trying to get a SMS project going demonstrating the use of CreateAndFillPrepare against a mormot SQLite Server. The documentation here http://blog.synopse.info/post/2014/08/11/CrossPlatform-Clients/SmartMobileStudio says that I should be able to create a wrapper with this functionality - but it just gives me the standard Calculator wrapper

You must create a service method on the server side and simply typing http://127.0.0.1:888/root/wrapper to generate smartmobilestudio wrapper client, and use the generated unit inside SMS client, like proj 27.

Quote

Smart Mobile Studio 3.1x

I spent hours debugging an issue because in SMS 3.1x I couldn't detect why it couldn't work like in the previous version 2.2x. I realized a lot of optimizations was done in the 3x, like the direct implementation without the intermediary Result variable in the function returning.  Anyway, I realized something was bit different from the previous version:

In version 3.1x, it emits this piece:
 

var TObject={
    $ClassName: "TObject",
    $Parent: null,
    ClassName: function (s) { return s.$ClassName },
    ClassType: function (s) { return s },
    ClassParent: function (s) { return s.$Parent },
    $Init: function (s) {},
    Create: function (s) { return s },
    Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s[prop] },
    Destroy$: function(s) { return s.ClassType.Destroy(s) },
    Free: function (s) { if (s!==null) s.ClassType.Destroy(s) }
}


 I propose this little change be made is SMS 3.1x:

Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },

This little issue fixed we can use Smart 3.1x with mORMot with no more errors.

sms_mormot.thumb.jpg.f0d792790f12cff74362817664cd25a1.jpg

Quote

Remote Logging

According to mORMot documentation, since there is no true file system API available under a HTML5 sand-boxed application, logging to a local file is not an option. Even when packaged with PhoneGap, local log files are not convenient to work with.

Generated logs will have the same methods and format as with Delphi or FreePascal - see Local or remote logging. TSQLRest.Log(E: Exception) method will also log the stack trace of the exception! Our LogView tool - Logview - is able to run as a simple but efficient remote log server and viewer, shared with regular or cross-platform units of the framework.

A dedicated asynchronous implementation has been refined for Smart Mobile Studio clients, so that several events will be gathered and sent at once to the remote server, to maximize bandwidth use and let the application be still responsive.
It allows even complex mobile applications to be debugged with ease, on any device, even over WiFi or 3G/4G networks. Your support could ask your customer to enable logging for a particular case, then see in real time what is wrong with your application.

You can use remote logging with smart Mobile Studio! It's cool.

I'll have to submit the CrossPlatform units to AB to generated the correct wrapper.

smartms_mormot.rar

Share this post


Link to post
Share on other sites
1 hour ago, warleyalex said:

I propose this little change be made is SMS 3.1x:


Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },

This little issue fixed we can use Smart 3.1x with mORMot with no more errors.

That code comes from DWScript. I had a look and the latest DWScript code also contains: delete s[prop] instead of delete s.prop

I'm pretty sure that DWScript in SMS 2.2 also had the same delete s[prop]

Do we have a JS guru here who could tell what the difference is? Because all pages I can find say that they both do the same thing. @lynkfs ???

Share this post


Link to post
Share on other sites

It is a bug!  SmartMS 2.2.2.4694 emits correct JS, it comes with delete s.prop

var myObject = {
    "ircEvent": "PRIVMSG",
    "method": "newURI",
    "regex": "^http://.*"
};
delete myObject.regex;
// it also work with
delete myObject['regex'];

Note

delete s[prop]

instead of

delete s["prop"]

Source: https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object

Share this post


Link to post
Share on other sites

Smart Mobile Studio Compiler version 1.2 emits this

var TObject={
	$ClassName: "TObject",
	$Parent: null,
	ClassName: function (s) { return s.$ClassName },
	ClassType: function (s) { return s },
	ClassParent: function (s) { return s.$Parent },
	$Init: function () {},
	Create: function (s) { return s },
	Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },
	Destroy$: function(s) { return s.ClassType.Destroy(s) },
	Free: function (s) { if (s!==null) s.ClassType.Destroy(s) }
};

 

Now, I've been thinking,  the correct is the SMS 3.1x that emits delete s[prop];

var myObject = {
    "ircEvent": "PRIVMSG",
    "method": "newURI",
    "regex": "^http://.*"
};

function destruir(s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s[prop] };

destruir(myObject);

It will remove all properties from JavaScript object myObject. ---> this is the expected!

The delete operator is more about freeing memory than deleting an element.

 

function destruir(s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop };
destruir(myObject);


delete s.prop --> don't delete properties ---> the myObject is still there: {ircEvent: "PRIVMSG", method: "newURI", regex: "^http://.*"}

I think we have the wrong delete s.prop in SMS 1.2 / 2.0 / 2.1 / 2.2 

Share this post


Link to post
Share on other sites
2 hours ago, warleyalex said:

I submitted the Destroy method issue to Eric Grange https://bitbucket.org/egrange/dwscript/issues/150/destroy-method

DWScript's Git repository uses:

dwsJSRTL.pas:               +#9'Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s[prop] },'#13#10

So if you think that delete s[prop] is the right one, DWScript is all ok.

The question then just is: Why does mORMot only work with delete s.prop, if it's wrong?

Share this post


Link to post
Share on other sites

In fact, there is an bug on older SMS versions 1.2 | 2.0 | 2.0.1 | 2.2 and 2.2.2 - the TObject::Destroy method would just delete the property named "prop" rather than the actually all the properties of the object itself. For instance, obj.Free is doing nothing because the method Destroy was buggy :)

// old SMS version
var TObject={
    (...)
    Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },
    Destroy$: function(s) { return s.ClassType.Destroy(s) },
    (...)
}

On newer SMS version 3.x, they fixed the TObject::Destroy method. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×