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

Лишний рендер для isPending #25

Open
zerkalica opened this issue Nov 19, 2016 · 4 comments
Open

Лишний рендер для isPending #25

zerkalica opened this issue Nov 19, 2016 · 4 comments

Comments

@zerkalica
Copy link

В примере ниже лишний: "c.subscribe: isPending: true, err: null, val: 5", т.к. данные сфетчились и записались, а потом еще отдельно isPending в false переключили

let a = new cellx.Cell((push, fail, old) => {
  setTimeout(() => {
    push(2)
  }, 100)
  return old || 1
})

let b = new cellx.Cell((push, fail, old) => {
  setTimeout(() => {
    push(3)
  }, 500)
  return old || 2
})


cellx.configure({asynchronous: false})
const c = new cellx.Cell(() => a.get() + b.get())
const d = new cellx.Cell(() => {
  return {
    v: c.get(),
    isPending: c.isPending(),
    error: c.getError()
  }
})

d.subscribe((err, {value}) => {
  console.log('c.subscribe: isPending: '+value.isPending + ', err: ' + (err ? err.message : 'null') + ', val: ' + value.v)
})

const v = d.get()
console.log('c.get:', v)
/*
"c.get:"
[object Object] {
  error: null,
  isPending: true,
  v: 3
}
"c.subscribe: isPending: true, err: null, val: 4"
"c.subscribe: isPending: true, err: null, val: 5"
"c.subscribe: isPending: false, err: null, val: 5"
*/

http://jsbin.com/padehafano/edit?js,console

@Riim
Copy link
Owner

Riim commented Nov 21, 2016

В синхронном режиме изменения не схлопываются, d зависит от c и c._pendingStatusCell, после второго push оба меняются и дважды происходит перерасчёт и обновление d.

@zerkalica
Copy link
Author

А там транзакцию внутри нельзя влепить? Или подскажи где ее тут влепить. По-логике все-таки это лишний рендер.

@Riim
Copy link
Owner

Riim commented Nov 21, 2016

подскажи где ее тут влепить

просто обернуть второй push в cellx.transact.

@zerkalica
Copy link
Author

let b = new cellx.Cell((push, fail, old) => {
  setTimeout(() => {
    cellx.transact(() => {
      push(3)
    })
  }, 500)
  return old || 2
})

Да, так работает, но как-то это не очевидно, видимо из-за неявной установки isPending перед pull.

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

No branches or pull requests

2 participants