These are chat archives for canjs/canjs

19th
Mar 2018
Kevin Phillips
@phillipskevin
Mar 19 2018 14:18
Awesome @nriesco. Glad to hear it.
Marc Godard
@MarcGodard
Mar 19 2018 15:04

Hi Guys, quick question... I have a model, and one of the variables is calculated as needed.

  items: {
    type: [ { itemId: 'string', quantity: 'number' } ],
    get (val) {
      return this.itemsList.reduce((list, item) => {
        list.push({ itemId: item._id, quantity: item.quantity })
        return list
      }, [])
    }
  },

This works when I need the variable, but doesn't when I save the model. If I use value instead of get, it does .save() that variable, but doesn't update it when I change it (obviously). Is this a bug where get isn't called on .save() but value is?

Oh btw, I am still using canJSv3
Justin Meyer
@justinbmeyer
Mar 19 2018 16:34
@MarcGodard use serialize: true
get is not serialized by default
only serialize-able properties are sent to the server
Marc Godard
@MarcGodard
Mar 19 2018 16:39
@justinbmeyer Thanks man, will do that :)
@justinbmeyer Works like a charm.
Justin Meyer
@justinbmeyer
Mar 19 2018 16:43
👍
Marc Godard
@MarcGodard
Mar 19 2018 19:23
Is there a way in the code to know if you are running production or development? In development things seem to run twice, and this causes issue sometimes. So if I am in development, I would like to put flags not to load things twice somehow... or is there a fix for running things twice? Before I would just turn off SSR in the code and that would make it work.
And when the page auto-reloads, it re-reloads the data making there be multiple copies. Any quick fixes on this, I know in production its good, just annoying in development.
Justin Meyer
@justinbmeyer
Mar 19 2018 22:53
@MarcGodard load what things twice?
CanJS should not load things twice
stealjs has an env flag that lets you know if you are in production
or some other environment