Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-13338

Ti API: implement features to add several listeners to a proxy in one call

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Low
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: TiAPI
    • Environment:

      Titanium API

      Description

      for example, it would be nice to have a method like Titanium.Proxy.addEventListeners( { } );

      var self = Ti.UI.createWindow({
      		
      	}); 
       
       
      self.addEventListeners(
      	{
      	 blur : function(e) { Ti.API.warn( JSON.stringify (e) ) } ,
      	
      	focus: function(e) { Ti.API.warn( JSON.stringify (e)) },
       
      	myEvent : function(e) { Ti.API.warn(  JSON.stringify (e)) },
      	}
       
       
      );
      

      to be clear I know, this can be done in Javascript ( but this means adding a method to Titanium.Proxy ) , and the idea here is not to call addEventListener in a loop but rather cross the bridge only once receiving a NSDictionary to transform callbacks in KrollCallbacks ( something like applyProperties()).

      for IOS my first try was to do :

      -(void)addEventListeners:(id)args
      {
          
          ENSURE_SINGLE_ARG(args, NSDictionary);
          
          for (NSString * currentKey in args)
          {
              KrollCallback*  currentListener = [args objectForKey:currentKey];
              ENSURE_TYPE(currentListener,KrollCallback);
              
              [self addEventListener: [NSArray arrayWithObjects:currentKey, currentListener, nil] ];
              
          }
          
      }
      

      This seems to work, but i'm safe to do that ?

      -Moreover would it be possible to pass a Dictionary of eventListeners in the Ti factory methods ?

      Ti.UI.createXXX({
      propertyX : value
      ...
      eventListeners : { .... } // is this possible for UI events ? custom events ? 
       
      })
      

      In some case , this could ensure that the listeners are registered before the events occur ( Ti.UI.Window events for example )

      • I saw that Alloy implement the on(..) off(..) method with event listeners, so another solution could be to use the same syntax in the Proxy create method:

        Ti.UI.createXXX({
        propertyX : value
        ...
        onClick = function(){}
        ...
         
        })
        
        

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                vince Vincent
              • Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration