w3c / miniapp-lifecycle

MiniApp Lifecycle
https://w3c.github.io/miniapp-lifecycle/
Other
7 stars 6 forks source link

change from callbacks to events #33

Closed QingAn closed 2 years ago

QingAn commented 2 years ago

Related to #30


Preview | Diff

QingAn commented 2 years ago

@Sharonzd, @MichaelWangzitao

As discussed during last week WG call. Please take a look.

MichaelWangzitao commented 2 years ago

I reviewed this PR, and basically, I agree to merge it to address #30 . In addition, I suggest adding the interaction process between the event handler and attributes. For example, when the event "ongloballaunched" is triggered, "globalState" should be set to "launched".

Sharonzd commented 2 years ago

I totally agree to change callbacks to events. From another perspective, this would make related code together, which This conforms to some code design principles like high cohesion. But we maybe need some examples of how to listen handlers? Like Page.registerLifeCycle( 'hide', hideEventHandler)

QingAn commented 2 years ago

@Sharonzd

I totally agree to change callbacks to events.

Thanks for reply.

From another perspective, this would make related code together, which This conforms to some code design principles like high cohesion. But we maybe need some examples of how to listen handlers? Like Page.registerLifeCycle( 'hide', hideEventHandler)

I agree. By looking at other related spec like Page Lifecycle, I am thinking of the example like:

const doGlobalLaunched = (inputObject) => { console.log(inputObject.pagePath); };

global.addEventListener('global launched', doGlobalLaunched);

QingAn commented 2 years ago

@MichaelWangzitao

I reviewed this PR, and basically, I agree to merge it to address #30 .

Thanks for reply.

In addition, I suggest adding the interaction process between the event handler and attributes. For example, when the event "ongloballaunched" is triggered, "globalState" should be set to "launched".

How about the wording like this: The ongloballaunched attribute is an event handler IDL attribute for the initialization event type. Once ongloballaunched is triggered, globalState will be set to launched.

MichaelWangzitao commented 2 years ago

@MichaelWangzitao

I reviewed this PR, and basically, I agree to merge it to address #30 .

Thanks for reply.

In addition, I suggest adding the interaction process between the event handler and attributes. For example, when the event "ongloballaunched" is triggered, "globalState" should be set to "launched".

How about the wording like this: The ongloballaunched attribute is an event handler IDL attribute for the initialization event type. Once ongloballaunched is triggered, globalState will be set to launched.

Agree!A brief description is good.