Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 14 21:13
    greenkeeper[bot] labeled #5378
  • Oct 14 21:12
    greenkeeper[bot] opened #5378
  • Oct 14 21:12

    greenkeeper[bot] on can-simple-map-4.3.3

    fix(package): update can-simple… (compare)

  • Oct 14 20:19
    greenkeeper[bot] labeled #5377
  • Oct 14 20:19
    greenkeeper[bot] opened #5377
  • Oct 14 20:19

    greenkeeper[bot] on @feathersjs

    chore(package): update @feather… (compare)

  • Oct 14 20:18
    greenkeeper[bot] labeled #5376
  • Oct 14 20:18
    greenkeeper[bot] opened #5376
  • Oct 14 20:18

    greenkeeper[bot] on @feathersjs

    chore(package): update @feather… (compare)

  • Oct 14 14:43
    greenkeeper[bot] closed #5373
  • Oct 14 14:43

    greenkeeper[bot] on can-deep-observable-1.0.1

    (compare)

  • Oct 14 14:42

    m-mujica on update-deep-observable

    (compare)

  • Oct 14 14:42

    m-mujica on master

    Update can-deep-observable to l… Merge pull request #5374 from c… (compare)

  • Oct 14 14:42
    m-mujica closed #5374
  • Oct 14 14:42
    m-mujica closed #5365
  • Oct 14 14:09
    f-ricci starred canjs/canjs
  • Oct 14 13:55
    greenkeeper[bot] commented #5375
  • Oct 14 13:55

    greenkeeper[bot] on core-js-3.3.2

    chore(package): update core-js … (compare)

  • Oct 14 10:51
    m-mujica review_requested #5374
  • Oct 14 07:43
    rjgotten commented #5358
Matthew Phillips
@matthewp
If you are using get then dimensionList is a compute. You can't replace it. You probably don't want a get in this case.
Chris Gomez
@akagomez
@opolyo01 Is this what you’re going for? http://jsbin.com/dagefe/1/edit?js,console
@matthewp We can replace computes on can.Map’s with { type: ‘compute’ }. It’s just not documented yet: bitovi/canjs#1690
opolyo01
@opolyo01
@akagomez Yes, I want something like this. Though, I am not sure I like this whole serialize thing. At first I can do -- map.attr('list') // [1, 2, 3] And after setting new array on the list I get a serialized object. Let me check that this will even auto update in my stache template if I keep serialized version of it
opolyo01
@opolyo01
@matthewp Ok so things with get should be immutable? But I thought the purpose of compute objects to be updated and bindable to a template. If I had a simple can.List outside of Map then everything would just work by updating the list, but what is the process of updating properties under can.Map within define?
Chris Gomez
@akagomez
@opolyo01 The serialize was for demonstration purposes only. Sorry to confuse.
@opolyo01 Here’s a better example: http://jsbin.com/dagefe/2/edit
Chris Gomez
@akagomez
@opolyo01 I think @matthewp Was misinterpretting your question. Computes are the low-level utility that backs can.Map.define. A compute takes a property on set… compute(newVal). So if you unknowingly attempted to set list to something else, like.. map.attr(‘list’, someOtherList), you’ll actually be passing someOtherList to the compute, like this.. map.list(someOtherList), as opposed to map.list = someOtherList. Does that make sense?
opolyo01
@opolyo01
Ok thanks. I found an issue. So get in can.Map define actually being called only if accepts an argument with the new value. I thought, by doing map.attr('list', someOtherList) it will automatically bind to template without me writing the logic in get. So now I have this define: {
dimensionList: {
get: function(filteredDimensions) { instead of define: {
dimensionList: {
get: function() {
Chris Gomez
@akagomez
Can you share your get function? Or maybe summarize it? I wonder if it’s actually necessary for your case.
opolyo01
@opolyo01
get: function(filteredDimensions) {
if(filteredDimensions){
return filteredDimensions;
}
else{//logic for returning original set of dimensions
Basically, I have search that filters for the list of dimensions to show
Chris Gomez
@akagomez
The reason I ask is that get is meant to describe a value that is made up of other values. And since that value is dependent on other values, the get function will only be evaluated when one of those dependent values are changed. In other words, map.attr(‘list’) won’t call get because none of its dependent values have changed. However, when you pass a value to the can.compute like this.. map.attr(‘computedProp’, anotherList) the compute re-evaluates due to the new lastSetVal.
Aside: In your original example you do this.scope.dimensionList(). That’s the incorrect way to read the value. What you should do instead is this.scope.attr(‘dimensionList’).
Okay, so you want an initial list, and you’d like to filter it on keyup?
opolyo01
@opolyo01
yeah
Chris Gomez
@akagomez
Gotcha.
opolyo01
@opolyo01
I am thinking to create a searchTerm compute that would be used inside of get for dimensionList
and then change searchTerm inside of the keyUp event
Chris Gomez
@akagomez
You can define a default with the value method. Provide it a function and it will populate that value for all new instances of the map if one isn’t passed when calling new.. new CustomMap(props).
That’s not a bad idea either.
opolyo01
@opolyo01
I am just trying to figure out where to throw this searchTerm variable
in the past I would simply do this.searchTerm = can.compute("")
but with can.Component.. would it belong in my can.Map
Chris Gomez
@akagomez
Yeah, in your view model.
(or scope if you haven’t made the change)
opolyo01
@opolyo01
Thanks, it works. Now I need to add "change, blur" on top of keyUp event and I am all set
Chris Gomez
@akagomez
Great! In the meantime, I put together this demo: http://jsbin.com/vusuzu/1/edit?js,console
I'm currently working on a much easier way to derive a bound, filtered list from another, so stay tuned: https://github.com/canjs/can-derive
opolyo01
@opolyo01
pretty useful
opolyo01
@opolyo01
Is it the correct way defining the same handler for multiple events
'.search-dimension keyup': this.searchTermChanged,
'.search-dimension change': this.searchTermChanged,
'.search-dimension blur': this.searchTermChanged,
        searchTermChanged: function(el, ev){
            var searchTerm = el.val();
            this.scope.attr('searchTerm', searchTerm);
        },
somehow it only works only if I do -- '.search-dimension keyup': function(el, ev)
Chris Gomez
@akagomez
@opolyo01 'el event
Whoops…
’el event’: ‘handler’
opolyo01
@opolyo01
nice
'.search-dimension keyup': 'searchTermChanged',
'.search-dimension change': 'searchTermChanged',
'.search-dimension blur': 'searchTermChanged',
'.search-dimension search': 'searchTermChanged',
works
Alex
@whitecolor

is is possible to to like this

{{#each items "item"}}

//refere tho current item as "item", not {.} or this
{{item}}

{{/#item}}

?

Alexis Abril
@alexisabril

Any reason why binding to a list internally would be a bad idea?

var Person = can.Map.extend({
  define: {
    items: {
      set: function(val) {
        val.bind('change', console.log);
        return val;
      }
    }
  }
});

I believe we clean up those bindings when a new “items” list is set and when the instance of person is destroyed, but can’t recall offhand #lazyweb

Alexis Abril
@alexisabril

also, should the can.List change event be adding nested properties to the index argument?

var list = new can.List();

list.bind(‘change’, function(ev, index) {});

var foo = new can.Map({ name: ‘foo’ });
list.push(foo); //index is 0, expected

foo.attr(‘name’, ‘bar’); //index is 0.name, I would expect 0

http://jsbin.com/cuqato/1/edit?js,output

Chris Gomez
@akagomez
@alexisabril For your second example (“0.name”), that seems right to me. Since the “name” property changed on the item in the “0” index position.
Isn’t that argument called “attr”, not “index”? Context matters.
Alexis Abril
@alexisabril
@akagomez that’s true, we do document “index” as where the change took place. perhaps my issue is with calling it “index” in the docs: “0.name” isn’t the index
Chris Gomez
@akagomez
Yeah. Understandable. In a simple list, “attr” would look like “index”.
Alexis Abril
@alexisabril

What’s everyone’s approach to abstracting out arbitrary data from a model?

For instance, suppose a user model:

{ id: 0, name: ‘Alexis’ }

However, in the template we would also want:

{ isEditing: false }

You wouldn’t want to add that attribute directly to the model as it has no benefit being sent back to the server(just view noise).

The elegant answer is inheritable defines(I think), but I’m curious what everyone’s approach has been thus far.

opolyo01
@opolyo01
@alexisabril I just usually have some _.map somewhere in controller code that being passed to the template. It is probably better to abstract in the UI model class like you do.
Well, I am currently stuck with another issue that might not be can.js related, but part of can.js application that uses clientState