Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] offlineListener preparation #2186

Merged
merged 30 commits into from
Nov 3, 2023
Merged

[main] offlineListener preparation #2186

merged 30 commits into from
Nov 3, 2023

Conversation

siyuniu-ms
Copy link
Contributor

No description provided.

@siyuniu-ms siyuniu-ms marked this pull request as ready for review October 25, 2023 22:07
function addListener(callback: OfflineCallback) {
listenerList.add(callback);
return {
rm: () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, the list should be an array and an edge case that has to be handled is that someone "could" call this rm function multiple times, so the first time will remove the entry (if present) and subsequent times will do nothing.

On way to do this is to use a temporary variable and then when rm is called you just reassign the rm function on that variable (that you return) to a function that does nothing.

Copy link
Contributor Author

@siyuniu-ms siyuniu-ms Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function addListener(callback: OfflineCallback) {
        listenerList.push(callback);
        const rm = (callback: OfflineCallback) => {
            let removed = false;
            return () => {
                if (!removed) {
                    const index = listenerList.indexOf(callback);
                    if (index !== -1) {
                        // Remove the callback from the list
                        listenerList.splice(index, 1);
                        removed = true; // Mark it as removed
                    }
                }
            };
        };
        return rm;
}

does this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it does not work, vs is complaining the type error

@siyuniu-ms siyuniu-ms requested a review from MSNev October 30, 2023 21:30
}

function setOnlineState (uState: eOfflineValue){
this.uState = uState;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the this is not required.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests for this as any tests should be failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not have any test on this new code yet, maybe we could merge this into karlie's offline branch instead of main branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current test is failing because of dep, I will rerun the rush update

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just push into main as we are now not planning any more releases from this branch until this feature set is complete.

If we need to release a version 3.0.5 we will create a branch for that release.

Copy link
Collaborator

@MSNev MSNev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets wait until we do the patch release before committing this, so that we don't have to branch.

@MSNev MSNev added this to the 3.0.x milestone Oct 31, 2023
Copy link
Collaborator

@MSNev MSNev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready to go

@siyuniu-ms siyuniu-ms merged commit 19e8131 into main Nov 3, 2023
8 checks passed
@siyuniu-ms siyuniu-ms deleted the siyu/offlineListener branch November 3, 2023 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants