Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Justin Meyer
@justinbmeyer
yeah
this is the problem
I suppose that live-binding should check if the parent element is a <select>
and make sure the value is maintained if possible
Chris Gomez
@akagomez
@justinbmeyer If you detach and append the exact same <option> elements, it shows the correctly selected option item: http://jsbin.com/tupodanihu/1/edit?html,js,output
Although I’m not really surprised by that now that I think of it.
Justin Meyer
@justinbmeyer
yeah, b/c of Selected
Chris Gomez
@akagomez
@justinbmeyer Shouldn't registered can.view.attr functions be run when the attribute is added post-render, like this: {{#if panelB}}st-panel-resizable{{/if}}
Matthew Phillips
@matthewp
I have a list of 5 items
I call .destroy() on one of them
I would expect the list to be 4
where is the logic where it gets spliced out of the list?
dylanrtt
@dylanrtt
Matthew Phillips
@matthewp
i think you're right
thanks
espretto
@espretto
hi there, i'm new to gitted and canjs, anybody home?
Chris Gomez
@akagomez
Welcome.
espretto
@espretto
great! could you help me with some canjs basics?
Chris Gomez
@akagomez
I’ll do my best.
espretto
@espretto
i've been working with emberjs and knockoutjs but am still struggling atm with canjs observables/computed attributes - hands on: how do you typically wire up model requests depending on some observable e.g. the route?
as suggested in the docs i created a computed representing the request deferred
can.Map.extend({
   model: null,
    state: 'pending', 

    promise: compute(function () {
      var scope = this,
          promise;

      promise = ConfigModel
        .findOne({
          version: scope.attr('version'),
          title: scope.attr('panoTitle')
        })
        .then(function (model) {
          scope.attr('model', model);
        })
        .always(function () {
          scope.attr('state', promise.state());
        })
        .promise();

      scope.attr('state', promise.state());

      return promise;
    })
});
problem is the promise doesn't evaluate its dependencies until someone binds to it
Chris Gomez
@akagomez
@espretto That’s by design.
espretto
@espretto
makes sense, now..

if i rewrite state to depend on promise

...
state: compute(function () {
  return this.attr('promise').state();
});
...

the binding won't get set up. i intend to request {{state}} in my stache template to trigger the request - if that's how it's supposed to be.

return this.promise().state() won't setup the dependency either.
neither does stache's live-binding
espretto
@espretto
the only solution to force computed properties to evaluate their dependencies was to add
Component.extend({
  ...
  scope: MapCtr,
  events: {
    '{scope} promise': noop,
    ...
  }
  ...
});
Chris Gomez
@akagomez
So this.attr(‘promise’) didn’t call the promise’ compute function?
espretto
@espretto

yes it did, however, state does not revaluate itself when promise does. i was expecting any call to .attr would bind the computed being created to that attribute, but it doesn't. which is why i tried sth. like

Component.extend({
  ...
  scope: {
    promise: '...',
    state: compute(function (newState) {
      if (arguments.length) return newState;
      var self = this;
      self.bind('promise', function (evt, newPromise) {
        newPromise.always(function () {
          self.attr('state', this.state());
        })
      })
    })
  }
  ...
});

but that doesn't work either.

i think i basically try to achieve sth. like amd can/list/promise does
Chris Gomez
@akagomez
Is the promise property changing? Or is the state of the promise property changing?
espretto
@espretto
the state depends on promise
and promise depends on panoTitle and version
Chris Gomez
@akagomez
And you’re saying that promise does not get re-evaluated when panoTitle or version change?
espretto
@espretto
only after the call to bind (not stache live-binding but can.Map#bind)
attr doesn't duffice
the call to bind i implemented through the component's events object which btw i don't understand the naming of - why not just control?
Chris Gomez
@akagomez
Are you changing panoTitle and version with .attr(‘panoTitle’)?
espretto
@espretto
yes i am - well, actually
<input can-value="panoTitle"/>
Chris Gomez
@akagomez
Seems like you’re doing it all right. I’m curious if you can reproduce in a JSBin so I can take a closer look.
espretto
@espretto
yes i'd like to! this is so exciting: i only recently came to want to contribute to such "bigger" projects, and canjs so far is doing a great job. the fiddle will take me a few minutes - how to notify you? how did you @ me? ah i see - easy
do you have time for another question? this one should be easier
Chris Gomez
@akagomez
Yeah, sure. If I can’t answer I’m sure somebody else will.
espretto
@espretto
i figured defining components is the way to go for nested views so i'm building my whole app of them. how do give viewModel/scope (are these the same?) computed properties access to dom elements? here is the draft:
Component.extend({
  scope: {
    question: computed(function () {
      return howToAccessThisComponentsElement; // ?
    })
  }
})
Chris Gomez
@akagomez
Yes, viewModel and scope are the same. scope was recently renamed to viewModel for various reasons.
We strongly discourage DOM manipulation from the scope.
espretto
@espretto
as of 2.3-pre? i'm working with 2.2
Chris Gomez
@akagomez
2.2 uses scope as an alias to viewModel.
In fact, our hope is that there is seldom a need to manipulate DOM outside of a template.