Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 17:59

    matthewp on can-observable-array-1.0.2

    (compare)

  • 17:59

    matthewp on master

    fix(package): update can-observ… Merge pull request #5388 from c… (compare)

  • 17:59
    matthewp closed #5388
  • 16:46
    greenkeeper[bot] labeled #5388
  • 16:46
    greenkeeper[bot] opened #5388
  • 16:46

    greenkeeper[bot] on can-observable-array-1.0.2

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

  • 12:45
    greenkeeper[bot] labeled #5387
  • 12:45
    greenkeeper[bot] opened #5387
  • 12:45

    greenkeeper[bot] on can-stache-element-1.0.2

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

  • 09:49
    chasenlehara edited #5384
  • 09:47
    chasenlehara edited #3864
  • 09:46
    chasenlehara edited #5383
  • Oct 17 20:12

    matthewp on master

    Update dist for release (compare)

  • Oct 17 20:12

    matthewp on v6.1.2

    Update dist for release 6.1.2 (compare)

  • Oct 17 20:04

    matthewp on master

    Update dist for release (compare)

  • Oct 17 20:04

    matthewp on v6.1.2-0

    Update dist for release 6.1.2-0 (compare)

  • Oct 17 19:17
    akbaruddin starred canjs/canjs
  • Oct 17 17:25
    matthewp edited #5384
  • Oct 17 17:00

    matthewp on can-dom-mutate-2.0.7

    (compare)

  • Oct 17 17:00

    matthewp on master

    fix(package): update can-dom-mu… Merge pull request #5386 from c… (compare)

Alexis Abril
@alexisabril
and then put all my conversions in there
I’m starting to get drawn back to the filters approach though

then you could do:

<input type=“radio” can-value=“{foo}” can-type=“boolean”/>
<input can-value=“{modifiedAt}” can-type=“date”/>
<input can-value=“{price}” can-format=“$dd.dd”/>

or something

those syntaxes were off the top of my head, don’t hold me to those ;)
Patrick Clancy
@patrickclancy
ahh interesting…. "a viewmodel inbetween the actual model” I’ll need to think about how to implement that. I like the can-type=“…” you’ve really got me thinking about the possible ways to skin the model cat.
Alexis Abril
@alexisabril
heh, I feel like I did a can-currency-value a while back for this type of stuff
I just want a normalized way to do conversions between the presentation/data layer elegantly
Gerard Finnerty
@halcyonandon
@alexisabril arent mustache helpers appropriate to use when you want the view format to be different than the data format? That's what I use for currency, date, et al. ...unless I'm misunderstanding the original question
Matthew Phillips
@matthewp
A viewModel is for the view. I would put it there.
dylanrtt
@dylanrtt
@halcyonandon if you are only displaying the data, mustache helpers are certainly appropriate, but if the data is being manipulated in the view, then you can do a lot more with the viewModel such as add setters and type conversions through the define plugin that you wouldn't necessarily want in your model, or at least that is what I am understanding
Chris Gomez
@akagomez
Is there a way to get compute A’s value from within compute B without creating a binding? @justinbmeyer @alexisabril
computeA.value seems to work.
Sorry to bug you.
Ilya Fadeev
@ilyavf
hey guys, how can i define a computed property in a child component and setup a reference to it in its parent component?
Ilya Fadeev
@ilyavf
var ChildVM = can.Map.extend({
  define: {
    myComputed: {
        get: function(){ return 'foo';}
    }
  }
});
can.Component.extend({
    tag: 'my-child',
    viewmodel: ChildVM
});
can.Component.extend({
    tag: 'my-parent',
    template: can.stache('<my-child myComputed="{getComputed}"></my-child>')
    viewmodel: {
        getComputed: null
    }
});
Chris Gomez
@akagomez
I was wrong earlier. It’s computeA.computeInstance.value.
dylanrtt
@dylanrtt
@ilyavf you can access the parent scope from the child to set properties like in this example:
http://jsbin.com/zoginopiwu/2/edit?html,js,console,output
but there might be a better approach to your problem if you could provide more info
opolyo01
@opolyo01
hey guys, I am stuck with updating dimensionList attribute of ViewModel
var ViewModel = {
isSelectedDimension: '',
define: {
dimensionList: {
get: function() {
Here's the event that tries to update it
'.search-dimension keyup': function(el, ev){
var searchTerm = el.val();
var filteredDimensions = _.filter(this.scope.dimensionList(), function(dim){
return dim.title.indexOf(searchTerm) !== -1;
});
this.scope.attr('dimensionList', filteredDimensions);
},
somehow this.scope.dimensionList() always stays the same
I haven't worked with can.Components much, so might be missing something fundamental
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