These are chat archives for canjs/canjs

26th
Jun 2017
Szabolcs Schmidt
@sszabolcs
Jun 26 2017 13:28

Hi!
After an update (I'm using CanJS 3) I've run into a strange operation and I cannot decide if it is a bug or feature?!
Here is a sample code.
It is a simple construction. my-main component loads items from a fixture and when it is finished it renders as many editors as many items there are. I'm logging to the console the init function calls and the inserted, removed events.
I would expect the following log:
main inited
main inserted
---editor inited
------my input inited
---editor inited
------my input inited
---editor inserted
------my input inserted
---editor inserted
------my input inserted

5 inits and 5 inserts.

But actually the log is this:
main inited
main inserted
---editor inited
------my input inited
---editor inited
------my input inited
---editor inited
------my input inited
---editor inited
------my input inited
---editor removed
------my input removed
---editor removed
------my input removed
---editor inserted
------my input inserted
---editor inserted
------my input inserted

9 inits, 4 removes and 5 inserts.

Is this an optimization related thing that there are 4 more inits and 4 more removes? Thanks!

gregorgodoy
@gregorgodoy
Jun 26 2017 13:38

Hi all! I have a issue with can-define-backup. Im trying to backup nested can-define-maps properties, but without success. The define-map has a property called quickbrief with an asynchronous getter like this:

quickbrief: {
        get(lastSetVal, resolve) {
            this.quickbriefPromise.then(quickbrief=>{
                quickbrief.backup();

                quickbrief.quickbrief_detail.forEach(function(quickbrief_detail){
                    quickbrief_detail.backup();
                });

                resolve(quickbrief);
            })
        }

    }

The quickbriefPromise returns a data structure like this:

{
  "quickbrief_id": 15,
  "customer_id": 2,
  "customer_brand_id": 1,
  "customer_product_id": 2,
  "created_at": "2017-06-23T16:12:59.934023-04:00",
  "benefit": "",
  "target": "",
  "impact": "",
  "quickbrief_detail": [
    {
      "quickbrief_id": 15,
      "product_id": 6,
      "parent_product_id": null,
      "date_completion": null,
      "description": "",
      "prize": 0
    }
  ]
}

So, im backing up the quickbrief defineMap and each quickbriefDetail. What im try to accomplish is to check wich canMap (representing a model) isDirty, so i can do a save() just in the dirty instances, like this:

var self = this;
if (this.quickbrief.isDirty()) {

                    self.quickbrief.save().then(qb=>{
                        console.log('quickbrief saved!');
                        self.quickbrief.backup();
                    });
}

self.quickbrief.quickbrief_detail.forEach(function(qd, index, list) {



                                if (qd.isDirty()) {

                                    qd.quickbrief_id = self.quickbrief.quickbrief_id;

                                    qd.save().then(detail=>{
                                        console.log('detail saved!');
                                        qd.backup();

                                    })
                                }

                    });

I know that i can do isDirty(true) to evaluate deep properties, but i want to know wich quickbrief_detail instance has changed, i just do a save to that instance. I hope you understand what im trying to accomplish. Is that possible with backup? The problem is each tiem i called backup(), the _backupStore is the overwritten for the quickbrief and the quickbrief_detail instance.

Gregg Roemhildt
@roemhildtg
Jun 26 2017 13:51
Hey guys, anyone know what's happening with travis builds/testee? quite recently tests started failing (according to testee due to browser timeout) on travis. The builds run fine in firefox/chrome on a local install but won't run on travis for some reason...
Kevin Phillips
@phillipskevin
Jun 26 2017 14:33
@roemhildtg it could be the Firefox version. We recently had trouble with the "latest" version of Firefox not existing, so Travis was defaulting to Firefox 31 which is very old. You could try using Firefox "51.0", which is what we use for most canjs tests in Travis.
Gregg Roemhildt
@roemhildtg
Jun 26 2017 14:34
I'll give that a shot, I'm using "54.0" at the moment. Is there a way to get testee to print out the browser console logs?
I think that would be helpful to see what firefox is complaining about
Gregg Roemhildt
@roemhildtg
Jun 26 2017 15:28
Well I enabled that debugging line but it didn't give any additional output. I have a line like this in travis.yml:

before_install:
  - "export DEBUG=testee:console-log"
Kevin Phillips
@phillipskevin
Jun 26 2017 15:41
looks fine to me
you can try DEBUG=testee:* to make sure it's working
Frank Lemanschik
@frank-dspeed
Jun 26 2017 15:42
oh kevin your there can you help me with a complex thinking problem
i now understood a bit more about can connect define map and that all and now i really wonder how i can do that with current tools
i have a socket.io connection that emits coins like this socket.on('coin', (coin)=> coin == 2)
i now need to set a value on the AppViewModel every time this emits
i don't need to add the coins i want that a function runs and changes 1 value
so i need to call a function that can change a value on AppViewModel how can i get that done?
and can-connect .connection don't helps me with that as this would create a instance for every coin thats not needed
Frank Lemanschik
@frank-dspeed
Jun 26 2017 15:48
i think i could build a solution with can-connect and connection when i use something like if instance update
but thats hacky isn't it?
Kevin Phillips
@phillipskevin
Jun 26 2017 15:49
You don't want to create an instance when this happens, right?
is that what you mean
Frank Lemanschik
@frank-dspeed
Jun 26 2017 15:50
right
i only need one computed value from the emitted one
that updates on emit
Single Value :)
Kevin Phillips
@phillipskevin
Jun 26 2017 15:50
but that computed value isn't an instance of your model?
it's just a value on your VM?
Frank Lemanschik
@frank-dspeed
Jun 26 2017 15:51
right its only a value of my view model its rest time
think about coding a arcade machine
its one
:D
we insert coins and get that via websocket
then we need to compute play time left
if it was 0 we start with gametime value like 1 coin 1 min so 1 min
is the value
if 1 gets emited
if there is value like 1 min then we add 2 min after secund emit with value 2
so computed value is 3
i need a way to get values send on event
set sorry not send lol
Kevin Phillips
@phillipskevin
Jun 26 2017 15:54
right
you could just create the socket connection in your viewmodel then
and not use can-connect at all
I don't know how you're going to tell the difference between different instances of your component though
Frank Lemanschik
@frank-dspeed
Jun 26 2017 15:55
there are no diffrent instances
its a one screen app
that screen shows simply time left
time left gets comuted by coins inserted
thats it
i am still wondering how setting the connection in the view model helps me to listen on it
and change a value
the only thing i got working is a one time value via
  get Socket() {
    return new Promise((resolve,reject) => {
      socket.on('connect',(socket) => {
          resolve('message: ');
      });
    })
  }
and that works
but i don't know how i could get updates for that :)
so i am always thinking about can-stream-kefir

if i could return kefir.stream(function(){

})

that listens and emits
or maybe i could do it in the init()
if that not blocks
Kevin Phillips
@phillipskevin
Jun 26 2017 16:14
init() {
  const socket = io('http...');
  socket.on('coin', (coin) => { this.coin = coin; });
}
wouldn't that do what you're trying to do?
Frank Lemanschik
@frank-dspeed
Jun 26 2017 16:16
maybe if that works i am not sure about if this works i am just trying this at present but when that works i need to code a set coin
to run my computation of the final value right?
Kevin Phillips
@phillipskevin
Jun 26 2017 16:17
yeah, you could derive a property from coin
Frank Lemanschik
@frank-dspeed
Jun 26 2017 16:18
ok i will try that i hope that works that would help me to create a lot of apps lets cross fingers
Gregg Roemhildt
@roemhildtg
Jun 26 2017 16:20
@phillipskevin I think testee itself is running, but its just not printing the console logs. My guess is that a package isn't loading correctly before testee loads in the browser perhaps? I was using the * debug before, and still not getting the browsers logs printed. You can see the build here:
https://travis-ci.org/roemhildtg/spectre-canjs
Frank Lemanschik
@frank-dspeed
Jun 26 2017 16:22
@phillipskevin nope that don't works
but i think because ssr
let me try
Frank Lemanschik
@frank-dspeed
Jun 26 2017 16:28
nope no way
even with executing it only in browser via steal-platform
i think in init the problem is that message for example is not defined
Frank Lemanschik
@frank-dspeed
Jun 26 2017 16:35
right in init() this === Array [ ]
i mean Object.keys === Array [ ]
i think i need simply a way to call a ViewModel function from stache
Kevin Phillips
@phillipskevin
Jun 26 2017 17:25
I'm not sure what you mean
Frank Lemanschik
@frank-dspeed
Jun 26 2017 17:25
on define map
Kevin Phillips
@phillipskevin
Jun 26 2017 17:25
the socket message shouldn't be received before the other properties are defined
Frank Lemanschik
@frank-dspeed
Jun 26 2017 17:27
i am wondering why this problem is so uncommun lol
Kevin Phillips
@phillipskevin
Jun 26 2017 17:28
I think it's uncommon to have a socket connection that isn't related to a model instance
Frank Lemanschik
@frank-dspeed
Jun 26 2017 17:28
ok
so can-connect is the only way
to get that into the view model right?
Kevin Phillips
@phillipskevin
Jun 26 2017 17:29
no, I'm not saying that
Frank Lemanschik
@frank-dspeed
Jun 26 2017 17:29
via custom behaviert
Kevin Phillips
@phillipskevin
Jun 26 2017 17:29
I think the code I gave you for init() should work
Frank Lemanschik
@frank-dspeed
Jun 26 2017 17:29
i am also messing around with can-compute
maybe i can design a pollyfill object
with a value prob
that changes on socket coin event
why can't can compute simple wrap a event emitter
and return the emittet value
that would be the solution
but its designed to listen for a event and then read a value
so i am now creating a eventEmitter with a value that can be read that internal uses socket.on
that should work probally
Frank Lemanschik
@frank-dspeed
Jun 26 2017 17:36
thanks for the help i will try tomorrow to use can-connect lol but this framework really needs solutions for taking values from events
Kevin Phillips
@phillipskevin
Jun 26 2017 18:06
this really doesn't seem like a framework problem
you're just trying to use socket.io
Frank Lemanschik
@frank-dspeed
Jun 26 2017 18:06
yes thats sure a problem
Kevin Phillips
@phillipskevin
Jun 26 2017 18:06
if you can give an example JSBin with what is not working we can try to help
Frank Lemanschik
@frank-dspeed
Jun 26 2017 18:07
i regonized that
no need i will find a way
but out of my view this is without framework
a task of 3 min
with framework this is really hard
lol
sorry for sarkasm i am burned out
Kevin Phillips
@phillipskevin
Jun 26 2017 18:07
it's ok
Frank Lemanschik
@frank-dspeed
Jun 26 2017 18:08
i am totall down the last days was so hard
i just found out my self that can-zone don't supports websockets after 1 year
always tought i did coding errors
it simply makes me mad
that there is no easy way for that
as its a standart case for me to use events
i do it server side always
eventEmitters are observeAble out of my view
Gregg Roemhildt
@roemhildtg
Jun 26 2017 18:17
running into another new issue today...anyone else getting errors like this? Potentially unhandled rejection [10] TypeError: Error loading "can-define@1.2.3#map/map" at http://.../static_apps/crud/node_modules/can-define/map/map.js
just updated all my can-* packages and steal/steal-tools
that is followed by this: Illegal module name "can-observation@https://registry.npmjs.org/can-observation/-/can-observation-3.1.4.tgz#can-observation"
steal.js:140 Potentially unhandled rejection [28] TypeError: Illegal module name "can-compute@https://registry.npmjs.org/can-compute/-/can-compute-3.0.10.tgz#can-compute"
Gregg Roemhildt
@roemhildtg
Jun 26 2017 18:41
Well, not sure what that issue was tbh. Somewhere between incompatible npm packages and browser caching I think... Oh well
Justin Meyer
@justinbmeyer
Jun 26 2017 20:42
@roemhildtg you re-installed and everything worked?
Gregg Roemhildt
@roemhildtg
Jun 26 2017 20:43
Well sort of, the files are loading correctly with steal now, I'm just running into an issue with can-reflect
Trying to reproduce, in a simple example but so far no luck. I've got a promise in a DefineMap that canReflect.isObservableLike returns true on for some reason which is causing an issue
Justin Meyer
@justinbmeyer
Jun 26 2017 20:53
hmmm
Gregg Roemhildt
@roemhildtg
Jun 26 2017 20:57
image.png
val[how] fails because val doesn't have a get property
I'll be looking into this tomorrow, gotta run for now
Kevin Phillips
@phillipskevin
Jun 26 2017 21:10
I just ran into a similar issue: canjs/can-define#224
working on a fix now
Justin Meyer
@justinbmeyer
Jun 26 2017 21:10
@roemhildtg where is that code?
yeah ... this seems like it should be using canReflect to do that read
Kevin Phillips
@phillipskevin
Jun 26 2017 21:11
yeah
this was the fix that was put in early friday because it was crashing done-serve 100% of the time
Justin Meyer
@justinbmeyer
Jun 26 2017 21:26
what was? using canReflect to do the read?
Kevin Phillips
@phillipskevin
Jun 26 2017 21:27
no, using canReflect at all there
canjs/can-define@10f4bd6