These are chat archives for canjs/canjs

16th
May 2017
Frank Lemanschik
@frank-dspeed
May 16 2017 05:14
can some one here give me a example of cache bust or any other good way to clear only canjs related local storage and cache stuff :)
Julian
@pYr0x
May 16 2017 07:14
steal cache bust ?
Julian
@pYr0x
May 16 2017 07:21
to clarify. i have a table that have some items. i create a new item by new Pruefbericht({}). that new item is added to the table. now i want to highlight this new row in the table. to check that i need a indicator what row (in the table) is created by new Pruefbericht({})
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 08:59
@pYr0x we had something similar, our solution is to do an action when the save promise is resolved.
newItem.save().then(function(item) {
    route.data.detailId = newItem.id;
    route.data.action       = 'focusTitle';
});
Julian
@pYr0x
May 16 2017 09:00
@jeroencornelissen is data.action a route param ? or do you serialize = false it
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 09:01
route.data.action changes the route
And I have an event binding on the route, so I could focus the the title input field
Julian
@pYr0x
May 16 2017 09:02
so you have onchange and then use jquery to find the element ?
and set foucusTitle on it?
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 09:03
yes
This is in my title component:
route.data.on('action', function(event, newValue, oldValue) {
    if(newValue === 'focusTitle') {
        if(self.viewModel.element) {
            const $input = self.viewModel.element.find('smsc-inlineeditor');
            $input.viewModel().selectAll();
        }
        route.data.action = undefined;
    }
});
(Inside the inserted event of the component)
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 09:09

I’m not saying you should do it with route. You could do something like:

newItem.save().then(function(item) {
    self.newListItemId = item.id;
});

And in your stache loop check if {{#is newListItemId loopItem.id}}active-class{{/is}}

but i think isNew is not available on the liste i iterate though
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 09:28
I think isNewis only true when it’s not saved.
Julian
@pYr0x
May 16 2017 09:28
Returns true if id is 0 or truthy.
?
Frank Lemanschik
@frank-dspeed
May 16 2017 09:29
i think we should look into bitballs
Julian
@pYr0x
May 16 2017 09:29
is 1234 not truthy?
Frank Lemanschik
@frank-dspeed
May 16 2017 09:29
its using isNew
:D
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 09:33
1234 is truthy :smile:
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 09:41
I think the docs are wrong. Should be: Returns true if id is 0 or falsey.
Frank Lemanschik
@frank-dspeed
May 16 2017 09:42
but 0 is a valid id
Guido Smeets
@gsmeets
May 16 2017 11:50
@justinbmeyer @matthewp is there any forward compatible DefineMap polyfill available for 2.X? I'm currently semi-rewriting a large chunk of my component library and I'm trying to get it as 3.X compatible as I can. But DefineMap for my viewmodels is a difficult one...
Matthew Phillips
@matthewp
May 16 2017 13:43
definemaps are 3.0 only
but, can-map still exists in 3.0
so no issue with having can maps if you plan on upgrading
you don't need to switch everything to definemap
Guido Smeets
@gsmeets
May 16 2017 17:48
yeah, but I use can.Map with the define plugin
and I want to synchronize the API
i.e. polyfill the 3.0 interface, so I can just drop the polyfill when I upgrade and it still works
Adam L Barrett
@BigAB
May 16 2017 17:56
What is that stache syntax for making an input disabled based on a boolean property?
something like <input {$disabled}="allowInput" /> or something?
Guido Smeets
@gsmeets
May 16 2017 17:57
<input {{#allowInput}}disabled{{/}} />
Adam L Barrett
@BigAB
May 16 2017 17:57
That might work, @gsmeets but I know there is a way closer to what I have there too
Guido Smeets
@gsmeets
May 16 2017 17:58
if that's possible then I'm interested as well, because I find that way of writing it a bit meh
Matthew Phillips
@matthewp
May 16 2017 18:03
@gsmeets maybe you could extend a can.map and use Object.defineProperty to call into .attr()
Chasen Le Hara
@chasenlehara
May 16 2017 18:03
@BigAB {$disabled}="allowInput" looks correct
Matthew Phillips
@matthewp
May 16 2017 18:03
then you'd be using can.Maps under the hood but syntax would look like define maps
Chasen Le Hara
@chasenlehara
May 16 2017 18:03
Guido Smeets
@gsmeets
May 16 2017 18:04
hmm, right, DefineMap uses proxies, doesn't it?
how's the support for that on IE browsers?
Kevin Phillips
@phillipskevin
May 16 2017 18:05
DefineMap uses getters/setters, not proxies
Guido Smeets
@gsmeets
May 16 2017 18:06
ah, so then it works for IE9+, right?
Kevin Phillips
@phillipskevin
May 16 2017 18:06
right
Adam L Barrett
@BigAB
May 16 2017 18:06
@chasenlehara Thanks Chasen, it doesn't seem to work for me, but that might be because I am using CanJS 2.3.23 ? I don't know. Thanks anyway.
Kevin Phillips
@phillipskevin
May 16 2017 18:07
make sure you import the can/view/bindings plugin @BigAB
Adam L Barrett
@BigAB
May 16 2017 18:08
In 2.3 @phillipskevin ?
Kevin Phillips
@phillipskevin
May 16 2017 18:08
yeah
can-stache-bindings in 3.0
I think it still had to be imported separately in 2.3
not positive
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 20:37
I have a MyMap DefineMap with a property children, I set the children to be a DefineList of the MyMap type like this:
var MyMap = DefineMap.extend({

    itemType: 'string',

    children: {
        type: function (newValue) {
            if (!(newValue instanceof MyMap.List)) {
                return new MyMap.List(newValue);
            } else {
                return newValue;
            }
        },
        value: []
    }
});
Is it possible to set itemType property of the root to all it’s children?
Chasen Le Hara
@chasenlehara
May 16 2017 21:10
Hi @jeroencornelissen, sorry I don’t 100% understand what you’re trying to do.
What does “set itemType property of the root to all it’s children” mean?
Jeroen Cornelissen
@jeroencornelissen
May 16 2017 21:12
I have one MyMap item (= root item), that has children and the children can have children.
The children should inherit the itemType property of the root item.
The children are all MyMap’s.
I think, I should make a forEach loop in the set function of children. But maybe there is a more simple solution.
@chasenlehara is this more clear?
Chasen Le Hara
@chasenlehara
May 16 2017 21:35
Yeah, thanks for explaining more.
Chasen Le Hara
@chasenlehara
May 16 2017 21:42
I think what I would do is have each instance point to its “parent” instance.
That way, you could have another property (maybe rootItemType) that walks up the parents to fetch the value.
That would keep it observable so the grandparent (or whatever) itemType can change.
If it’s never modified and doesn’t need to be observable, you could get away with just assigning the value when you create the list, like you said.