Skip to content

Commit

Permalink
feat: a change watcher system to proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
0Lilian committed Sep 7, 2022
1 parent 2b51c86 commit 879f850
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/composables/proxies/proxy.js
Expand Up @@ -76,16 +76,27 @@ export class TulipeProxy {
});

this.proxy = {
_changeWatchers: [],
onChange: (callback) => {
this._changeWatchers.push(callback)
},
_initIsRunning: false,
_ethersInstance: null,
get ethersInstance () {
return this._ethersInstance;
},
set ethersInstance(instance) {

const oldInstance = {...this._ethersInstance};

// Set the new ethersInstance
this._ethersInstance = instance ? markRaw(instance) : instance;

// Call change watchers
for (const changeWatcher of this._changeWatchers) {
changeWatcher(this._ethersInstance, oldInstance);
}

// Re-initialize with the new ethersInstance
if (!this._initIsRunning) {
this._initIsRunning = true;
Expand Down

0 comments on commit 879f850

Please sign in to comment.