These are chat archives for canjs/canjs

9th
May 2017
Julian
@pYr0x
May 09 2017 00:44
@phillipskevin are you there?
i thought you worked on can-route?
https://canjs.com/doc/can-stache.helpers.routeUrl.html the example at the bottom is not working. the same for my little app. the route is not changing becauase the "page" is not changing.
Kevin Phillips
@phillipskevin
May 09 2017 01:36
yeah, I see that
can you open an issue? I can investigate in the morning.
Eben
@eben-roux
May 09 2017 06:28
hi, I'm using can-connect and am setting a header using this:
$.ajaxPrefilter(function(options, originalOptions) {
    options.beforeSend = function(xhr) {
        if (security.token) {
            xhr.setRequestHeader('sentinel-sessiontoken', security.token);
        }

        if (originalOptions.beforeSend) {
            originalOptions.beforeSend(xhr);
        }
    };
});
However, my header is not being sent. Is there anything in particular I need to be aware of when using can-connect?
Julian
@pYr0x
May 09 2017 07:31
@phillipskevin did canjs/canjs#3208
thanks
Kevin Phillips
@phillipskevin
May 09 2017 14:08
thanks @pYr0x
@eben-roux you can check here if can-connect is using jQuery.ajax: https://github.com/canjs/can-connect/blob/master/can/base-map/base-map.js#L32
if not, you can pass it as the ajax option
DaveO
@DaveO-Home
May 09 2017 15:46
@phillipskevin sorry for the delay on your asm.js request, golf is more important. The dependency on asm is empty, I'm just wondering about steal/asm because all of the browsers started using it, chrome, ff, ms etc.
DaveO
@DaveO-Home
May 09 2017 16:06
@phillipskevin I get these:
Successfully compiled asm.js code (total compilation time 19ms; unable to cache asm.js in synchronous scripts; try loading asm.js via <script async> or createElement('script')) steal.production.js
Successfully compiled asm.js code (total compilation time 128ms; unable to cache asm.js in synchronous scripts; try loading asm.js via <script async> or createElement('script')) steal.production.js
Successfully compiled asm.js code (total compilation time 35ms; unable to cache asm.js in synchronous scripts; try loading asm.js via <script async> or createElement('script')) steal.production.js
Successfully compiled asm.js code (total compilation time 7ms; not stored in cache (too small to benefit))
Kevin Phillips
@phillipskevin
May 09 2017 16:15
can you look for asm.js in System._traceData.parentMap in your browser console
DaveO
@DaveO-Home
May 09 2017 16:24
I'm sure how to do that, using ff
I meant "not"
Kevin Phillips
@phillipskevin
May 09 2017 16:29
press the Ctrl+Shift+K (Command+Option+K on OS X) keyboard shortcut.
Then just type System._traceData.parentMap and try to find something that says asm.js
DaveO
@DaveO-Home
May 09 2017 16:34
I get asmcrypto, I am using this..
However, I believe I was getting asm.js before I started using crypto.
Eben
@eben-roux
May 09 2017 16:42

@phillipskevin That seemed to do the trick. I am defining my model like this:

connect([constructor, data, map], {
    url: loader.serviceBaseURL + 'users/{id}/roles',
    Map: Model,
    List: Model.List,
    name: 'user-role',
    ajax: $.ajax
});

but am now getting this error: TypeError: connection.addInstanceReference is not a function
I have a suspicion it has to do with the can-connect

My motivation behind this is that I don't want caching and the superMap seems to be doing just that...
Kevin Phillips
@phillipskevin
May 09 2017 18:59
yeah, I would guess you are missing some behaviors
I can’t tell exactly what those methods are that you’re passing to connect
but try starting with https://github.com/canjs/can-connect/blob/master/can/super-map/super-map.js#L22-L32 and removing what you don’t want
Brad Momberger
@bmomberger-bitovi
May 09 2017 19:01
You need constructor/store (can-connect behavior) for addInstanceReference
Eben
@eben-roux
May 09 2017 19:01
ah, thanks... was going to dig through some of this tomorrow :)
Brad Momberger
@bmomberger-bitovi
May 09 2017 19:07
Some of us (okay, me) have been trying to improve how opaque can-connect can be for users. Last week I rewrote the code for ordering the included behaviors that also involved behaviors declaring their own dependencies. It won't be published in mainline because it creates another issue that you can't just provide the dependencies in another behavior without occupying the same name.
Kevin Phillips
@phillipskevin
May 09 2017 19:07
someone else is working on that also
Brad Momberger
@bmomberger-bitovi
May 09 2017 19:07
Justin has an idea for how to declare interfaces, that we'd use in can-connect when it's implemented
Kevin Phillips
@phillipskevin
May 09 2017 19:07
so it will eventually get in
yeah @nlundquist is taking a look at how to do this
Brad Momberger
@bmomberger-bitovi
May 09 2017 19:08
Until then, you need constructor/store here, and if you do real-time you need data/callbacks.
Eben
@eben-roux
May 09 2017 19:11
thanks, that was the one
I quite like where it is heading and it makes it quite flexible
but yes... having dependencies between behaviours can be troublesome
it will be interesting to see what you come up with w.r.t. interfaces... being all typeless and such
Julian
@pYr0x
May 09 2017 20:17
is there a way easy create an inverse of a prop by clicking a button
<button class="btn btn-primary btn-sm" {($click)}="!changeAddress">Anschrift ändern</button>
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:19
set('changeAddress', not(changeAddress)) should do it.
Julian
@pYr0x
May 09 2017 20:21
<button class="btn btn-primary btn-sm" {($click)}="set('changeAddress', not(changeAddress))">Anschrift ändern</button>
?
doesnt work
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:22
Click is an event, so you want to use ($click) instead of {($click)} which is a two-way data binding
Julian
@pYr0x
May 09 2017 20:24
right.
but it works not
i know why
wait a sec
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:25
I'm noticing that too. I always get back undefined from not() in jsbin
Julian
@pYr0x
May 09 2017 20:26
nope. i thought i forget to import can-stache-converters
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:28
Interesting, equal() also keeps giving me undefined.
Kevin Phillips
@phillipskevin
May 09 2017 20:28
is can-stache-converters included in jsbin?
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:29
I'm using CanJS 3.6.0's global dist.
so yes if they're in that.
Kevin Phillips
@phillipskevin
May 09 2017 20:29
yeah, they are
Julian
@pYr0x
May 09 2017 20:30
i think the not converter is not called inside a set
i think we do not parse the set value ?
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:31
Might be right on that one. It could at that point be treated as a scope lookup only
Julian
@pYr0x
May 09 2017 20:32
yep, maybe
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:36
Can't do it right at this moment but I'd like to dive into this and see what the options are.
In the meantime, you could write a "toggle" function on your view model.
Julian
@pYr0x
May 09 2017 20:39
tried to create a helper
i am wrong? i cant create a helper for a click event
?
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:41
helpers object or viewModel object on your component?
Julian
@pYr0x
May 09 2017 20:41
´<button class="btn btn-primary btn-sm" ($click)="{{inverse ~changeAddress}}">Anschrift ändern</button>´
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:41
oh, use Call syntax rather than stache tags
($click)="inverse(~changeAddress)"
Julian
@pYr0x
May 09 2017 20:41
but i cant access a helper with call expression
?
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:42
Put it on the view model. Using tilde syntax you should (I'm not 100% sure) get a compute as the arg.
that’s how I would do it
maybe...
Julian
@pYr0x
May 09 2017 20:44
ok, thx, so you would create it on the VM
Julian
@pYr0x
May 09 2017 20:44
i thought i can create a global helper
Brad Momberger
@bmomberger-bitovi
May 09 2017 20:44
As an alternative where you use computes and not quoted key names.
Kevin Phillips
@phillipskevin
May 09 2017 20:44
you could
Julian
@pYr0x
May 09 2017 20:45
i couldnt
cant call a helper inside a click event
Kevin Phillips
@phillipskevin
May 09 2017 20:46
hmm
checking
ups
lmagarian
@lmagarian
May 09 2017 20:56
I updated can-connect to 1.3.11 and now I see this error message in my browser console:
I did a rm -rf on node-modules and npm update but still get the error
my app is working... but it is concerning
Julian
@pYr0x
May 09 2017 20:58
seems that you have multiple can-uitl
what steal version?
and npm version?
lmagarian
@lmagarian
May 09 2017 20:59
steal ^1.0.5
Julian
@pYr0x
May 09 2017 20:59
npm version
lmagarian
@lmagarian
May 09 2017 21:00
npm: '4.1.2'
Julian
@pYr0x
May 09 2017 21:00
does a node_modules exist in can-obvervation?
Brad Momberger
@bmomberger-bitovi
May 09 2017 21:01
@pYr0x In general if you do a global helper you'd have to make the helper do the click binding.
Julian
@pYr0x
May 09 2017 21:02
how?
Brad Momberger
@bmomberger-bitovi
May 09 2017 21:02
stache.registerHelper("toggleOnClick", function(compute, options) {
   return function(el) {
      el.addEventListener("click", function() {
         compute(!compute());
     });
   };
})
lmagarian
@lmagarian
May 09 2017 21:03
no
Julian
@pYr0x
May 09 2017 21:03
@bmomberger-bitovi but this is not memory save
Brad Momberger
@bmomberger-bitovi
May 09 2017 21:03
then <button {{toggleOnClick foo}}/>
Julian
@pYr0x
May 09 2017 21:04
@lmagarian pls try to install can-util in your package.json
lmagarian
@lmagarian
May 09 2017 21:04
I am already "can-util": "=3.2.2",
Julian
@pYr0x
May 09 2017 21:05
why =
put ^
lmagarian
@lmagarian
May 09 2017 21:05
ok, I'll try that. I don't know why it was =
Julian
@pYr0x
May 09 2017 21:05
you always can use 1 can-util
lmagarian
@lmagarian
May 09 2017 21:19
New error now: can-control.js:430 Uncaught TypeError: Cannot read property 'splice' of undefined
at Constructor.destroy (can-control.js:430)
at Constructor.destroy (control.js:70)
at HTMLElement.eval (can-control.js:113)
at eval (can-jquery.js:59)
lmagarian
@lmagarian
May 09 2017 21:24
I'm not explicitly installing can-control in my app but it is present in node-modules
"spec": "3.0.5"
Julian
@pYr0x
May 09 2017 21:32
why i cant access the viewModel of a component ? $('x-pruefbericht-creation').viewModel()
do i need can-jquery-legacy
Frank Lemanschik
@frank-dspeed
May 09 2017 21:33
no i think its a extra setting
Julian
@pYr0x
May 09 2017 21:33
extra setting?
Frank Lemanschik
@frank-dspeed
May 09 2017 21:33
there was something that this viewModel is only use able in dev mode
are you using ssr?
Julian
@pYr0x
May 09 2017 21:33
nope
Frank Lemanschik
@frank-dspeed
May 09 2017 21:33
your using a production build?
Julian
@pYr0x
May 09 2017 21:33
no
Frank Lemanschik
@frank-dspeed
May 09 2017 21:33
ok steal 1.0 right?
Julian
@pYr0x
May 09 2017 21:33
yep
but what does steal have to do with viewModel()?
Frank Lemanschik
@frank-dspeed
May 09 2017 21:34
i think a lot as this loads and exports all that
in its own context
Kevin Phillips
@phillipskevin
May 09 2017 21:34
Julian
@pYr0x
May 09 2017 21:34
i have can-jquery installed
Kevin Phillips
@phillipskevin
May 09 2017 21:35
so import $ from ‘can-jquery’; should work
Frank Lemanschik
@frank-dspeed
May 09 2017 21:36
@phillipskevin do you know if can-jquery is in general compatible to all jquery versions?
Julian
@pYr0x
May 09 2017 21:36
yep worked.. forgot to require it.
that multimain pages with steal is horrible. you always have to check your dependencies and check if they all required
Frank Lemanschik
@frank-dspeed
May 09 2017 21:38
what do you mean when you say check if they are required?
check if they are required in the code?
isn't that always needed also with clear html that you load the dependencys needed for what ever you do ?
this looks solved to me isn't it?
Julian
@pYr0x
May 09 2017 22:32
how can i nested a DefineMap
in canjs 2 i can nested with define a map
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:33
I think you mean this:
DefineMap.extend({ 
  foo: { 
    Type: { 
      bar: { 
         type: "string" 
        } 
      } 
   } 
})
Julian
@pYr0x
May 09 2017 22:33
?
yep exactly ! thans ;) i am lost...
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:35
Don't forget that that doesn't set a default value. If you need foo to exist when your object is created, also specify value: {}
Julian
@pYr0x
May 09 2017 22:35
probeuntersuchung: {
    Type: {
      anschrift: "string",
      schutz: {
        value: true,
        type: "boolean"
      },
      freigabe: {
        value: true,
        type: "boolean"
      },
      nachuntersuchung: {
        value: true
      }
    }
  }
but i got an error#
Potentially unhandled rejection [1] TypeError: Cannot read property 'schutz' of undefined
<input class="form-check-input" type="checkbox" {($checked)}="probeuntersuchung.schutz"> Dokumentenschutz (PDF)
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:36
:point_up_2: look at my last comment
Julian
@pYr0x
May 09 2017 22:36
schutz value is set to "true"
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:37
but probeuntersuchung isn't an object yet.
Julian
@pYr0x
May 09 2017 22:37
so probeuntersuchung should be an empty object?
probeuntersuchung: {
    value: {},
    Type: {
      anschrift: "string",
      schutz: {
        value: true,
        type: "boolean"
      },
      freigabe: {
        value: true,
        type: "boolean"
      },
      nachuntersuchung: {
        value: true
      }
    }
  }
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:38
value: {} passes an empty object to the ad hoc constructor created for that DefineMap property.
Julian
@pYr0x
May 09 2017 22:38
that's weird
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:39
so it will create the object with defaults you have defined them
Now you can also forget the Type and just use value with a plain object (or a function that returns a plain object).
That will be converted into a DefineMap with no prototype defines
if you just need values there and don't need to coerce types or use getter/setters, it's an option.
Julian
@pYr0x
May 09 2017 22:46
this DefineMap (created with value) is sealed false?
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:46
correct, because it will be strictly a DefineMap (not sealed by default) versus a subclass (sealed by default)
Julian
@pYr0x
May 09 2017 22:48
ok thanks
@frank-dspeed what i mean, is, that i have multiple entry points for my application. each index.js have to load the whole can-js modules
and sometimes i forget to require a module that i require in a different index.js before
so can-jquery i required in a index.js main, but forgot to require it on a different index.js
Brad Momberger
@bmomberger-bitovi
May 09 2017 22:53
Ah yeah that's always bugged me. I think that's what configDependencies is for now, but it's not yet documented on stealjs.com
Frank Lemanschik
@frank-dspeed
May 09 2017 23:57
why should a app have multiple index points
and if modules are shared why not import a shared_modules.js
that exports them