These are chat archives for canjs/canjs

27th
Jan 2016
Jani Mikkonen
@rasjani
Jan 27 2016 00:02
i think there might be something amiss once more in cjs builds in npm ..
David Luecke
@daffl
Jan 27 2016 00:04
@rasjani What specifically?
Jani Mikkonen
@rasjani
Jan 27 2016 00:07
Module not found: Error: Cannot resolve module '@loader' in /Users/janimikkonen/src/js/canjs_webpack/node_modules/can/dist/cjs/view/stache
i didnt go throught the recent code changes but, it looks like other builds do have many references to ourDefine which sets this '@loader' but dist/cjs has none ..
Jani Mikkonen
@rasjani
Jan 27 2016 00:12
that is from 3.2.10
and i know webpack aint the thing but i'm oddball, i'll dig into this on my own .. there was also another in can.define that could be easily fixed with IIFE
Jani Mikkonen
@rasjani
Jan 27 2016 00:39
@daffl 90cac21242ad967000feaed4a54abbf266a5a97d and on map/define/define.js .. it triggers invalid syntax on return with webpack ..
and the @loader issue came in with e27d0047d5e01e626454d23f176a4e5da42b6a14 .. view/stache/add_bundles.js
oh well, sleepy time now.
Kyle Gifford
@kylegifford
Jan 27 2016 00:52
I have a can.Model that has a can.compute as an instance property. I want to override the compute in an instance of the model, but I'm not able to do it like a normal instance property or method. Is there any way to accomplish this? Here's an example: http://jsbin.com/duvahaxavu/1/edit?html,js,console
Kevin Phillips
@phillipskevin
Jan 27 2016 01:22
@kylegifford why does it need to be a compute?
Kyle Gifford
@kylegifford
Jan 27 2016 01:37
because I need a method but want to access it with .attr()
it doesn't have to be but that's the cleanest way to accomplish what we're doing (mostly instance props + a few methods accessed generically through something like .attr(prop))
would like to avoid if(_.isFunction(model[prop])) model[prop](); else model.attr(prop); kind of thing
plus it seems like something that should be able to be replaced out of principle :)
Kevin Phillips
@phillipskevin
Jan 27 2016 01:41
not sure if it will work with instanceProps, but you could try something like this: http://jsbin.com/yijakonite/1/edit?html,js,console
with staticProps I mean
Kyle Gifford
@kylegifford
Jan 27 2016 01:48
it would have to be in the define right?
... shoot, my JSBin didn't save right
let me get my good example back
Kevin Phillips
@phillipskevin
Jan 27 2016 01:50
I think so, yes
Kyle Gifford
@kylegifford
Jan 27 2016 01:55
Here's a better example, sorry about that: http://jsbin.com/zoxuselosu/edit?html,js,console
Kevin Phillips
@phillipskevin
Jan 27 2016 02:02
ugly extra ()
but otherwise maybe does what you want?
well, probably doesn't
Kyle Gifford
@kylegifford
Jan 27 2016 02:10
I think I'd still have to do an _.isFunction(model['compute']) then
to know whether to add the extra ()
in which case, I can just use methods
Curtis Cummings
@ccummings
Jan 27 2016 02:12
define has a ‘compute’ type:
http://jsbin.com/sukimuniya/edit?html,js,console
Kyle Gifford
@kylegifford
Jan 27 2016 02:15
cool, I think I can make that work
Kyle Gifford
@kylegifford
Jan 27 2016 06:04
just a note for anyone following this, I had to move my define call into the Model's instance properties, as I received this message: The define property should be on the map's prototype properties, not the static properies.
but otherwise it works
although @justinbmeyer, i'd like to get your thoughts when you have a chance on why you can't just straight override a can.compute instance without using the define plugin like you can with a map method or property.
Dovid Bleier
@dbleier
Jan 27 2016 14:06
I have some config data set up by app.js that is needed by various components. I was thinking instead of having to pass around a config obj and inject it into every component, to write the data to localstorage and then any component that needs the config data can just read it from there. Is there any reason why this is not a good idea or that there is a benefit to passing around a config object? The data shouldn't change during the session, so I don't think it needs to be observable, which is the only reason I can think of to pass around an obj.
Matthew Phillips
@matthewp
Jan 27 2016 14:32
can you make it a module?
config.js
and then import that module anywhere it is needed?
Justin Meyer
@justinbmeyer
Jan 27 2016 15:35
@kylegifford
compute: can.compute(function() {
    return 'instanceCompute';
  })
is deprecated
i'd like to get your thoughts when you have a chance on why you can't just straight override a can.compute instance without using the define plugin like you can with a map method or property.
because when you do a compute on the prototype
well .. taking a step back
when a compute is setup on a prototype ... it's actually creating brand new compute instances on instances of that map
it's a weird setup
I'm not sure how to describe it
but notice that you are putting a compute on the prototype
but that compute actually acts like a define.get
in order to make that work, we clone that compute whenever a new instance is created
it's weird, which is why that is deprecated
Kyle Gifford
@kylegifford
Jan 27 2016 17:29
I see - so is creating a compute through the define plugin the only "right" way to add a compute to a Map then? or is there another way I'm missing?
Justin Meyer
@justinbmeyer
Jan 27 2016 18:03
@kylegifford I'm not sure what you mean by a "compute to a map" specifically
if you are asking if it's the right way to have a "attribute value automatically update from other attributes" then yes
Kyle Gifford
@kylegifford
Jan 27 2016 18:10
yes, that's what i was asking. thanks.
Perhaps we should update the can.compute Derived Computes docs section to link to the define plugin's type page's compute section?
might make it a bit clearer that it can't be put directly on the prototype
Kyle Gifford
@kylegifford
Jan 27 2016 18:15
LMK and I'll open an issue/update if desired
Or maybe on the can.Map.attr docs - not sure which would be better
Dovid Bleier
@dbleier
Jan 27 2016 18:18
@matthewp , how will a config.js module help pushing around data? When I would import it, wouldn't need to create a new instance of the object, in which case it wouldn't have the data. While the data doesn't change during the session, it is still determined at runtime, so it couldn't be hard coded or put in a config file. Or am I missing something?