B4J Question [BANano] [SOLVED]How to use On event with BANanoObject?

Solution
With the little information I got, I can only assume that 'on' here is just a method of the db object so you could try something like this:

B4X:
dim change as Object
db.RunMehod("on", BANano.Callback(Me, "DoChange", change))
...
Sub DoChange(change as Object)
     log(change)
End Sub

The next version of BANano will allow anonymous functions declared like this:
B4X:
Dim DoChange As BANanoObject
Dim change As Object
DoChange.Sub(change)
        Log(change)
DoChange.EndSub
    
db.RunMethod("on", DoChange)

Alwaysbusy

alwaysbusy

Expert
Licensed User
Longtime User
With the little information I got, I can only assume that 'on' here is just a method of the db object so you could try something like this:

B4X:
dim change as Object
db.RunMehod("on", BANano.Callback(Me, "DoChange", change))
...
Sub DoChange(change as Object)
     log(change)
End Sub

The next version of BANano will allow anonymous functions declared like this:
B4X:
Dim DoChange As BANanoObject
Dim change As Object
DoChange.Sub(change)
        Log(change)
DoChange.EndSub
    
db.RunMethod("on", DoChange)

Alwaysbusy
 
Upvote 1
Solution

Mashiane

Expert
Licensed User
Longtime User
Thank you so much...

This seems to be some kind of permanent feature in js. I guess my confusion was that they called the assignment events. Now I see here they call them lifecycle hooks.


B4X:
// Global hooks
editor.on("component:create", function (model) {
  return console.log('Global hook: component:create', model.get('type'));
});
editor.on("component:mount", function (model) {
  return console.log('Global hook: component:mount', model.get('type'));
});
editor.on("component:update:testprop", function (model) {
  return console.log('Global hook: component:update:testprop', model.get('type'));
});
editor.on("component:remove", function (model) {
  return console.log('Global hook: component:remove', model.get('type'));
});

So as an example, my definition as per advise given is...

B4X:
Dim mdl As Object
    Dim cc As BANanoObject = BANano.CallBack(Me, "component_create", Array(mdl))
    editor.RunMethod("on", Array("component:create", cc))

B4X:
Sub component_create(mdl As BANanoObject)
    Log("component_create...")
    Log(mdl)
End Sub

and it has logged something indeed... now I know...

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…