These are chat archives for canjs/canjs

11th
Jun 2015
opolyo01
@opolyo01
Jun 11 2015 17:20
does this look right?
if ( ! promiseStore [ key ] ) {
promiseStore[ key ] = $.ajax({
url: can.sub(steal.config('API')[ type ], params, true),
data: params,
type: 'GET',
dataType: 'json',
// work around the ajax bug in chrome
cache: false
});
return promiseStore[ key ];
}
else{
var dfd = $.Deferred();
dfd.promise(promiseStore[ key ]);
dfd.resolve( JSON.parse(promiseStore[ key ].responseText) );
return promiseStore[ key ];
}
dylanrtt
@dylanrtt
Jun 11 2015 17:52

@opolyo01 you can probably do it exactly like the QuickCache example. just copy the makeFindAll function out so it's independent and call it like this

var TodoModel = can.Model.extend({
  findTodos: makeCacheable(function(){
    return $.ajax(/*params*/);
  })
}, {});

That should allow you to make any request function cacheable. You can still use it with the standard find methods like this:

var QuickCacheModel = can.Model.extend({
  makeFindAll: makeCacheable
}, {});
Curtis Cummings
@ccummings
Jun 11 2015 20:02
I’m trying to create a nested Map that can have children that are the same type. Here’s a jsbin of the setup: http://jsbin.com/peyesififu/1/edit
Depending on what’s defined first I can either have the list be the right type or the map, but not both
dylanrtt
@dylanrtt
Jun 11 2015 20:07
@ccummings I had this issue before. Basically one of them needs to be defined before you can reference it in the other. I solved this by modifying the define block of one prototype after declaring both http://jsbin.com/yosakoqozo/1/edit?html,js,console
Curtis Cummings
@ccummings
Jun 11 2015 20:08
My brain must be fried. I can also modify the static Map parameter of the list after both are defined
both ways will work. Thanks!
Ilya Fadeev
@ilyavf
Jun 11 2015 20:56
hey guys, how can i listen to a list element's property change?
var Row = can.Map({
    define: {
        isChecked: {
            type: 'boolean'
        }
    }
});
var VM = can.Map({
    define: {
        items: {
            Type: Row.List
        }
    }
});
can.Component.extend({
    events: {
        '{scope.items. ??? .isChecked} change': function(){ 
            console.log('item is checked'); 
        }
    }
});
opolyo01
@opolyo01
Jun 11 2015 21:13
Hey guys, I am facing an issue where I have 3 Deferreds, and only first one resolves. Other two getting rejected, even though they are all the same deferreds. Any idea?
basically, it is 3 $.ajax deferreds that should have ".then" to have a callback executed, but only first then getting executed. If I do from chrome console it works fine
David Luecke
@daffl
Jun 11 2015 21:24
What's the reason for the other Deferreds to get rejected?
Justin Meyer
@justinbmeyer
Jun 11 2015 21:24
@ilyavf why are you doing this?
Ilya Fadeev
@ilyavf
Jun 11 2015 21:25
@justinbmeyer I have a grid with rows and i need to maintain a hash map of selected rows
opolyo01
@opolyo01
Jun 11 2015 21:25
@daffl no idea why is getting reject when I call this from my components
if ( ! promiseStore [ key ] ) {
                promiseStore[ key ] = $.ajax({
                    url: can.sub(steal.config('API')[ type ], params, true),
                    data: params,
                    type: 'GET',
                    dataType: 'json',
                    // work around the ajax bug in chrome
                    cache: false
                });

            }
promiseStore[ key ].then(function(resp){
console.log(resp);
});

return promiseStore[ key ];
Justin Meyer
@justinbmeyer
Jun 11 2015 21:26
@ilyavf can you do this w/ a compute instead
opolyo01
@opolyo01
Jun 11 2015 21:26
3 components will call this model and I get 3 console.log printed
Justin Meyer
@justinbmeyer
Jun 11 2015 21:26
@opolyo01 can you put that in a ```
@patrickclancy regarding model validation ... I would not use our validation plugin
it's probably more simple to use the define plugin
Patrick Clancy
@patrickclancy
Jun 11 2015 21:28
@justinbmeyer how would you suggest using the define plugin?
Ilya Fadeev
@ilyavf
Jun 11 2015 21:29
@justinbmeyer Like, have a compute property which iterates through my list of items and reads item's property I am interested to listen to?
Patrick Clancy
@patrickclancy
Jun 11 2015 21:29
with getters and setters
Justin Meyer
@justinbmeyer
Jun 11 2015 21:30
@patrickclancy something like:
define: {
  isNameValid: {
    get: function(){
      return !!this.attr("name")
    }
  }
}
and you could create "mixins" that help set this up
define: validators({}, validateExists("name"))
opolyo01
@opolyo01
Jun 11 2015 21:31
@daffl So yeah, promiseStore[ key ].then will be rejected within my components scope, but no while I am in the model. So I wonder would could reject the promise? I know I don't do .reject anywhere
Justin Meyer
@justinbmeyer
Jun 11 2015 21:31
@ilyavf yes
do this in the view model
Patrick Clancy
@patrickclancy
Jun 11 2015 21:43
@justinbmeyer interesting… I like using the define plugin… everything else is there. I’d need to roll in the check all type functionality that model.errors() provides. But that wouldn’t be hard
Justin Meyer
@justinbmeyer
Jun 11 2015 21:59
yeah, the check functionality
is the one thing that this is missing
but in my opinion, having observability
is more important
oh, you mean check all
nm, that can be observable too
I am talking about the "if I set this, will it create an error"
behavior of validations
so you don't actually have to commit a breaking set
to see if there's an error
Patrick Clancy
@patrickclancy
Jun 11 2015 22:01
@justinbmeyer is this the direction you’re thinking validation will go? We’ve got models with 60+ fields and observable is important. Bummer I just spent all day doing it the old way
@justinbmeyer I haven’t used this workflow "if I set this, will it create an error”. becasue of can-value live binding. I’d like to integrate that but haven’t
Justin Meyer
@justinbmeyer
Jun 11 2015 22:04
yes, validation will certainly be observable
and probably be a plugin into the define plugin itself
if validations are important I can help you create something that bridges the gap
are you using stealjs?
Patrick Clancy
@patrickclancy
Jun 11 2015 22:06
yes with ES6 syntax
Justin Meyer
@justinbmeyer
Jun 11 2015 22:06
If you are using StealJS, we could create a can-validate repo and add you as a contributor
Patrick Clancy
@patrickclancy
Jun 11 2015 22:07
wow… sounds good
Justin Meyer
@justinbmeyer
Jun 11 2015 22:07
either @daffl or I could put a day in or so to get the basics working
@patrickclancy added you to: https://github.com/canjs/can-validate
can you create an issue with what you'd like?
perhaps something very close to the old validation but observable
oh, @patrickclancy using npm to install deps hopefully?
@daffl anyway you can setup a "shell" project sometime tomorrow? It can look like can-connect
btw, @patrickclancy not sure if you've seen can-connect
but I am aiming to have the docs done this week
Patrick Clancy
@patrickclancy
Jun 11 2015 22:10
@justinbmeyer YES!! the only way to go. (can 2.3-pre as well)
@justinbmeyer I’ve seen can-connect and I’d like to use it but… docs would help
Justin Meyer
@justinbmeyer
Jun 11 2015 22:12
ok, great, that will make working on can-validate stupidly easy
Patrick Clancy
@patrickclancy
Jun 11 2015 22:12
@justinbmeyer Is place my order the best way to see can-connect in action?
Justin Meyer
@justinbmeyer
Jun 11 2015 22:13
currently yes, but my docs will have demos
Patrick Clancy
@patrickclancy
Jun 11 2015 22:17
@justinbmeyer sweet… thank you