[nosdk] use constructor instead of initialize in actors and fronts that inherit Actor/Front classes

NEW
Unassigned

Status

DevTools
General
P3
enhancement
10 months ago
10 days ago

People

(Reporter: jdescottes, Unassigned)

Tracking

(Blocks: 1 bug)

unspecified
Bug Flags:
qe-verify -

Firefox Tracking Flags

(Not tracked)

Details

All fronts and actors inheriting the base Front and Actor classes defined in protocol.js are relying on "initialize" being the constructor of Front and Actor. 

We should update each and every front/actor as follows:

> Front.prototype.initialize.call(this, [...]);

should become

> Front.call(this, [...]);

(same for Actor)

Once this is done, the initialize methods exposed on both Actor and Front can be removed.

Then Actor Front and Pool (which is extended by Actor and Front) could be migrated to ES6 classes.

Finally we can migrate fronts and actors to use classes rather than objects:

> const AnimationPlayerFront = FrontClassWithSpec(animationPlayerSpec, {
>   initialize: function (conn, form, detail, ctx) {
>     Front.call(this, conn, form, detail, ctx);
>     // ...
>   },
> 
>   form: function (form, detail) {
>     // ...
>   },
> 
>   destroy: function () {
>     Front.prototype.destroy.call(this);
>   },
> });

to

> const AnimationPlayerFront = FrontClassWithSpec(animationPlayerSpec, class extends Front {
>   constructor(conn, form, detail, ctx) {
>     super(conn, form, detail, ctx);
>   }
> 
>   form(form, detail) {
>     [...]
>   }
> 
>   destroy() {
>     super.destroy();
>   }
> });

Updated

10 months ago
Flags: qe-verify-
(Reporter)

Comment 1

10 months ago
I gave this a shot today and switching fronts and actor to ES6 classes will be challenging for another reason. We are using protocol.custom() and protocol.preEvent() to decorate some methods of Front prototypes. 

I think we will have to keep using the old extend() approach for the time being.

Updated

9 months ago
Severity: normal → enhancement
Blocks: 1402832
No longer blocks: 1378862
Whiteboard: [reserve-nosdk]

Updated

10 days ago
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.