These are chat archives for canjs/canjs

5th
Jan 2016
Chris Gomez
@akagomez
Jan 05 2016 05:14
@justinbmeyer I looked up can.viewModel() to see if I could do that (set an element’s viewModel). I was attempting to supply a define’d can.Map to can.route and the autorendered element. Creating a component wasn’t such a big deal though.
richardudovich
@richardudovich
Jan 05 2016 12:31
hey all
anyone around here?
i was just wandering... most router components allow you to use regex and various rules to enforce parameters in rules... like /foo/:id {where id needs to be an integer}
is there any way of doing that in canjs?
Chris Gomez
@akagomez
Jan 05 2016 14:42

@matthewp

I attempted to use the <bit-c3> component in my project and got this error, any ideas why?

steal.js:140 Potentially unhandled rejection [5] Error loading "bit-c3@0.0.5#bit-c3.less!$less" at <unknown>
Error loading "bit-c3@0.0.5#bit-c3.less!$less" from "bit-c3@0.0.5#bit-c3" at http://localhost/~akagomez/bitovi/can-derive/node_modules/bit-c3/src/bit-c3.js
Error loading "$less" at http://localhost/~akagomez/bitovi/can-derive/node_modules/steal/ext/less.js
Error evaluating http://localhost/~akagomez/bitovi/can-derive/node_modules/steal/ext/less.js
Uncaught Error: Unable to load dependency less@2.4.0#index. (WARNING: non-Error used)
Matthew Phillips
@matthewp
Jan 05 2016 14:59
something depends on less 2.4.0
not sure what, but should npmIgnore it
Chris Gomez
@akagomez
Jan 05 2016 15:01
Matthew Phillips
@matthewp
Jan 05 2016 15:02
steal's own package.json should be ignored automatically already
Chris Gomez
@akagomez
Jan 05 2016 15:02
Maybe it’s because I’m on a slightly older version of Steal.
Matthew Phillips
@matthewp
Jan 05 2016 15:03
which?
i think steal's package.json has been ignored as long as npm support has existed
Chris Gomez
@akagomez
Jan 05 2016 15:04
1.10.0
Matthew Phillips
@matthewp
Jan 05 2016 15:04
0.10 i presume
pretty sure it's a different issue
Chris Gomez
@akagomez
Jan 05 2016 15:05
Yeah. Upgrading didn’t help.
Didn’t hurt either though, so that’s good news.
Matthew Phillips
@matthewp
Jan 05 2016 15:05
you could also do a map
"map": { "less": "@less-engine" }
"paths": { "@less-engine": "node_modules/steal/ext/less.js" }
Adam L Barrett
@BigAB
Jan 05 2016 15:13
@richardudovich I don’t know the answer but i am curious as well
Kevin Phillips
@phillipskevin
Jan 05 2016 15:15
@richardudovich if you’re using can.route.map you can use the define plugin on your map to handle the validation / type conversion
richardudovich
@richardudovich
Jan 05 2016 23:34
@phillipskevin i have seen people mention this a few times but never an actual example of how to do it...
right now... im leaning towards integrating crossroadsjs and combining that with {can.route} change event ...
this will also not enforce me to have all my routes in a single file
Kevin Phillips
@phillipskevin
Jan 05 2016 23:37
it depends what you want to do
if you just want to make sure id is a number, it would be something like this
var appState = new can.Map({
  define: {
    id: {
      type: 'number'
    }
  }
});
can.route.map(appState);
if you want to prevent it from changing if it’s not a number, something like
var appState = new can.Map({
  define: {
    id: {
      set: function(newVal) {
        if (!_.isNumber(newVal)) {
          return this.attr(‘id’);
        }
        return newVal; 
      }
    }
  }
});
can.route.map(appState);
richardudovich
@richardudovich
Jan 05 2016 23:46
so... if i got 2 routes... "products/:product_id route" ---> where product_id needs to be an integer and "products/faq route" how can i differentiate between the 2?
richardudovich
@richardudovich
Jan 05 2016 23:58
?