BALKANGraph / FamilyTreeJS

Build family tree app with BALKAN FamilyTreeJS library. Family Tree also called a genealogy or a pedigree chart, is a chart representing family relationships in a conventional tree structure.
50 stars 16 forks source link

Remove event listener #78

Closed pandabytes closed 9 months ago

pandabytes commented 9 months ago

Hello!

After registering a callback to certain events like familyTree.onUpdateNode, how do I unregister the same callback from familyTree?

ZornitsaPesheva commented 9 months ago

Created a code demo for you: https://code.balkan.app/family-tree-js/remove-events-on-update#JS

pandabytes commented 9 months ago

Thanks @ZornitsaPesheva . The example you show removes the "update" listener from all FamilyTree objects right? What if I only want remove the "update" listener from one FamilyTree object? For example

function updateListener_1(args) {}
function updateListener_2(args) {}

const familyTree_1 = new FamilyTree(...);
const familyTree_2 = new FamilyTree(...);

familyTree_1.onUpdateNode(updateListener_1);
familyTree_2.onUpdateNode(updateListener_2);

// Is it possible to unresgiter updateListener_1 from familyTree_1?
plamen-peshev commented 9 months ago

we have added removeListener method for you

clear your browser cache and test this code demo

pandabytes commented 9 months ago

Nice! Thank you so much!