Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Filter works incorrectly if fields are splitted by several log actions #115

@LexxFedoroff

Description

@LexxFedoroff

Hello, I've debugged this issue logux/examples#21 and found that there is a bug in the filters.
I can reproduce it with a simple test:

it('filter works correctly if sent not all fields', async () => {
  let client = new TestClient('10')
  await client.connect()
  client.log.keepActions()

  let posts = createFilter(client, Post, { authorId: '1'})
  let unbind = posts.listen(() => {})
  await allTasks()

  await client.server.sendAll({ channel: 'posts/1', type: 'logux/subscribed' })
  await client.server.sendAll({
    fields: { title: 'A' },
    id: '1',
    type: 'posts/created'
  })
  await client.server.sendAll({
    fields: { authorId: '1' },
    id: '1',
    type: 'posts/changed'
  })
  await allTasks()

  expect(ensureLoaded(posts.get()).list).toEqual([
    { id: '1', isLoading: false, title: 'A', authorId: '1' },
  ])
  unbind()
})

I want to fix it but I need some information on how that should work.
As I understand we need to accumulate log actions for an object until we receive the fields required for a filter.
What is the best way to achieve this?
Version: 0.21.1

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