share / share/sharedb

Projection's nested fields aren't being updated when subscribing to a query

Open
#365 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
JavaScript
Stars
6.5k
Forks
456
Avg merge
1d 5h
Merged PRs (30d)
5

Description

Created a projection as follows:

  backend.addProjection 'gameInfos', 'games',
    id: true
    testGame: true
    host: true
    classIds: true
    createdAt: true    
    mode: true
    'scenario.name': true
    'scenario.labels.publish': true
    'scenario.labels.unpublish': true
    'scenario.scenarioName': true
    'scenario.playedAt': true
    'scenario.gameCategory': true
    'scenario.gameType': true
    'scenario.password': true
    'scenario.roles': true

Subscribed to a regular query:

   $games = @model.query 'gameInfos', someQuery
   @model.subscribe $games, =>
       @model.ref '_page.games', $games
       @page.render ...

All first-level nested fields, e.g. mode, host are being reactively updated. But the specified nested fields, e.g. scenario.name are not.
It will work fine if I pass just scenario: true into addProjection, i.e. all nested fields under scenario object will be updated reactively, but what if I only want a subset of the nested fields.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the addProjection and model.subscribe example with dotted fields such as scenario.name and compare it with a projection using scenario: true. Trace how nested projection fields are handled during query subscription updates; done means the specified nested fields update reactively without subscribing to every field under scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, javascript
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.