Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Create an $event object type in the Angular namespace for scope events. #7088

@thinkingmedia

Description

@thinkingmedia

Overview

The $rootScope.$on event listener method will pass event as the first parameter. This event object has a documented set of properties and methods.

Problem

This event object is not defined in a namespace and has no definition. It's an inline object defined in the $boardcast function.

This means it can not be defined as a parameter type for event listeners.

For example;

    /**
     * @param {*} event
     * @param {string} key
     */
    function onBoardTypeChanged(event,key)
    {
               //.....
    }
    $scope.$on("myEvent",onBoardTypeChanged);

Improvement

Create a javascript object in the angular namespace called $event that will be documented using JSDoc the object's properties and methods. This would allow developers to see intellisense auto-complete for event parameters.

The signature of $event would not change. So not problems with backward compatibility.

This would allow developers to define the parameter type for events.

    /**
     * @param {$event} event
     * @param {string} key
     */
    function onBoardTypeChanged(event,key)
    {
               //.....
    }
    $scope.$on("myEvent",onBoardTypeChanged);

Changes

Could be implemented as a constructor function in rootScope.js. Something like this.

    $event: function(name, target) {
          this.name = name;
          this.targetScope = target,
          this.preventDefault = function() {
             this.defaultPrevented = true;
          }.bind(this);
          this.defaultPrevented = false;
    },

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions