These are chat archives for ractivejs/ractive

7th
Nov 2018
Cerem Cem ASLAN
@ceremcem
Nov 07 2018 16:56 UTC
@evs-chris I remember we discussed that before but I don't remember what was the overall resolution:
I frequently need to set values silently and currently I'm using observer's handle's .silence() and .resume() methods
would there a logical issue to have a set option, like {silent: true} which prevents firing any observers which observe it?
like
this.set('foo', 5, {silent: true})
Chris Reeves
@evs-chris
Nov 07 2018 18:21 UTC
are you only trying to avoid observers or just all updates in general?
cause if you want no updates, you can just update the data directly
skipping just observers would be a challenge, since they're just plain old deps like a mustache or computation
Cerem Cem ASLAN
@ceremcem
Nov 07 2018 18:24 UTC
my use case is generally for avoiding circular dependency (infinite update loop)
for example, I'm creating a component that uses some other js library under the hood, say ace
inside my-ace-editor's onrender, I'm doing the following:
this.observe('content', function(val){
  editor.setContent(val)
})

editor.on('change', (val) => {
  this.set('content', val)
})
...which causes an infinite loop when editor content is changed
correct version would be either:
var handle = this.observe('content', function(val){
  editor.setContent(val)
})

editor.on('change', (val) => {
  handle.silence()
  this.set('content', val)
  handle.resume()
})
Cerem Cem ASLAN
@ceremcem
Nov 07 2018 18:31 UTC
or :
var internal = false;
this.observe('content', function(val){
  if (internal) {
    return 
  }
  editor.setContent(val)
})

editor.on('change', (val) => {
  internal = true
  this.set('content', val)
  internal = false
})
we can't assign beforeSet and afterSet handlers, can we?
Chris Reeves
@evs-chris
Nov 07 2018 18:59 UTC
there are deferred observers, but that has to do with when they fire in relation to dom updates
in your case, I'd think you only want to silence the setting observer, in case some attaches an observer to the content for other purposes, like persistence or dirty tracking
Cerem Cem ASLAN
@ceremcem
Nov 07 2018 19:05 UTC

I'd think you only want to silence the setting observer

I'm not sure I could get the difference

Chris Reeves
@evs-chris
Nov 07 2018 19:08 UTC
for instance: <my-ace-editor content="{{some.text}}" /> with the parent doing this.observe('some.text', v => sendToServer(v)), silencing the whole set would also silence the parent's observer
Cerem Cem ASLAN
@ceremcem
Nov 07 2018 19:10 UTC
hmm. got it and I agree
okay, I can give up on laziness and be happy using .silence() & .resume() methods :)