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

unsubscribe listenToChanges firestore #1508

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

snehmehta
Copy link
Collaborator

ticket: #1468

Issue:
Conditional will rebuilt it's children from scratch on data changes, so tabbar will always be created new and have index 0.

Solution:
Unsubscribe to changes onTab change and resubscribe to changes when needed again.

View:
  styles:
    useSafeArea: true

  header:
    titleText: Tab issue
  

  onLoad: 
    invokeAPI:
      name: getUsers
      inputs:
        listen: true
      

  body:
    Column:
      styles:
        padding: 24
        gap: 8
      children:
        - Conditional:
            conditions:
              - if: ${ensemble.storage.data != null}
                widget:
                  TabBar:
                    id: liveTabBar
                    styles:
                      tabAlignment: center
                    onTabSelection:
                      executeConditionalAction:
                        conditions:
                          - if: ${liveTabBar.selectedIndex != 0}
                            action: 
                              invokeAPI:
                                name: getUsers
                                inputs: 
                                  listen: false
                          - else:
                            action:
                              invokeAPI:
                                name: getUsers
                                inputs: 
                                  listen: true

                    items:
                      - label: Hello
                        widget:
                          Event:
                            inputs:
                              data: ${ensemble.storage.data}
                      - label: world
                        widget: 
                          Text:
                            text: world

Event:
  inputs:
    - data
  body:
    Text:
      text: ${data}


API:
  getUsers:
    inputs:
      - listen
    type: firestore
    path: matches
    onResponse:
      executeCode:
        body: |-
          ensemble.storage.data = response.body.documents[0].data;
    listenForChanges: listen

@snehmehta snehmehta requested review from vusters and kmahmood74 July 26, 2024 15:12
if (!isChangeListener) {
if (apiProvider is LiveAPIProvider) {
await (apiProvider as LiveAPIProvider)
.unSubscribeToApi(action.apiName);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we need to consider the API's with the same name but different IDs. The use case there is calling the same API with different inputs and using the API's id to bind it to different widgets. This code will cancel subscriptions for any existing APIs with the same name but different ids

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree. I'll implement once I prioritise it.

@kmahmood74
Copy link
Collaborator

@snehmehta any update on this, this has been pending since July which means we still have this issue?

@kmahmood74
Copy link
Collaborator

@snehmehta any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants