Skip to content

Computed property with subready in it is not working. Watch on subready is not working either. #26

Closed
@abhima9yu

Description

@abhima9yu

I have a case where a subscription should take place only when the other subscription is ready.

I could not find any subscription ready hook in the documentation. So I tried a few things with the following code but faced the problems mentioned in the comments.

    export default
      data: ->
        filter: null

      computed:
        filterSubscriptionReady: ->
          #this gets called when the filter subscription changes. 
          @$subReady.filter

        userSubscriptionReady: ->
          # this gets called only once and the value does not change even when $subReady.users changes.
          @$subReady.users
       

      meteor:
        $subscribe:
          filter: []
        filter: -> Filter.findOne()

      watch:
        '$subReady.filter': (value) ->
          console.log('this watch is not working')
          if value
            @$subscribe('users', @filter)
        '$subReady': (value) ->
          console.log('this watch is not working either')
        'filter': (value) ->
          # this will work but i can not use this as I need the below subscription to run even when there is no filter in the db.
          if value
            @$subscribe('users', @filter)

I can do null handling in publication but in the above case when filter is not present, there is a default value for filter in the publication.The problem is when the filter subscription is not ready users data is returned with default filter value. The users subscription gets called again when the filter subscription is ready.

Note: The above case is not exactly the same as I am facing in the project so I apologize if I missed something and the question is not clear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions