intercellular / cell

A self-driving web app framework
https://www.celljs.org
MIT License
1.5k stars 93 forks source link

Destructor #118

Open davidbonnet opened 7 years ago

davidbonnet commented 7 years ago

Motivation

Components currently support the $init callback that fires when the element is generated for the first time. This enables construction logic such as enabling a specific behaviour, issuing an API call or, as outlined here, subscribing to an observable.

However, the lifetime of an element might come to an end, typically due to a user action (e.g., closing a widget which removes a bunch of elements). In this case, it becomes necessary to terminate all ongoing transactions created by this element, such as cancelling API calls or unsubscribing from an observable. Such logic typically resides in a destructor callback, which could be called $deinit.

What about adding such callback? Or what would be the alternatives?

gliechtenstein commented 7 years ago

This is a great idea, thanks for bringing it up.

$deinit is nice but how about $destroy? Or if anyone has another suggestion, please feel free to share.

piranna commented 7 years ago

I find $destroy nicer.

davidbonnet commented 7 years ago

I was under Swift influence with $deinit, but $destroy is indeed better. Thanks to the prefix, we could even use $delete.

idkjs commented 7 years ago

Might want to reserver $delete for something later on.

ghost commented 7 years ago

$destroy +1