These are chat archives for canjs/canjs

3rd
Aug 2016
Guido Smeets
@gsmeets
Aug 03 2016 11:17
anyone happen to have any experience wrapping js from c#?
Matthew Phillips
@matthewp
Aug 03 2016 13:09
@the-learning-man that's true, you are welcome to use 3.0-pre if you want
2.3 is not reliant on steal either, there are commonjs builds
but 3.0 is written in cjs so it will be even more "compatible", I guess that's true
but there are definitely people using webpack/browserify already
Mason Shin
@minsooshin
Aug 03 2016 17:29
anyone can help how to use helper method of component in the QUnit test?
helpers: {
    prettify(count, type) {
    const pluralizedType = pluralize(type, count);

    if (count === 0) {
      return `No ${pluralizedType}`;
    }
    return `${count} ${pluralizedType}`;
  }
}
I have a helper method like this
import { ViewModel } from './confirmation’;

QUnit.module('Confirmation page of OOBE', {
  setup: function() {
    this.vm = new ViewModel();
    const template = can.stache('<sc-confirmation />');

    $('#qunit-fixture').html(template());

    this.$component = F('#qunit-fixture').find('sc-confirmation');
    this.vm = can.viewModel(this.$component);
  }
});
Kevin Phillips
@phillipskevin
Aug 03 2016 17:30
you could just export that function from your module
Mason Shin
@minsooshin
Aug 03 2016 17:30
this is my test setup
Kevin Phillips
@phillipskevin
Aug 03 2016 17:32
export function prettify(count, type) {
  const pluralizedType = pluralize(type, count);

  if (count === 0) {
    return `No ${pluralizedType}`;
  }
  return `${count} ${pluralizedType}`;
}

...

helpers: {
  prettify
}
Mason Shin
@minsooshin
Aug 03 2016 17:32
got it
that totally makes sense
thanks
Kevin Phillips
@phillipskevin
Aug 03 2016 17:34
you could also test it by testing the DOM wherever it’s used
but that would be a lot more work
Mason Shin
@minsooshin
Aug 03 2016 17:43
yes, that’s what I thought… need to take out all the helper methods out of component object.
I am looking for functional test for helper methods
Christopher Oliphant
@RALifeCoach
Aug 03 2016 18:31
hello - I’m back
I am now trying to create a simple page with a back end rest api
I am struggling to get the connection to the backend working
I know it’s in the docs … somewhere … but I have spent quite abit of time trying to get it to work
I am using superMap
the url is localhost:8787, but I can’t find how to reference a port
Thomas Sieverding
@Bajix
Aug 03 2016 19:11
@RALifeCoach
User.List = can.List.extend({
  Map: User
}, {});

var connection = superMap({
  url: {
    resource: config.hosts.api + '/users'
  },
  idProp: '_id',
  Map: User,
  List: User.List,
  name: 'user'
});
Also, it’s not good practice to use localhost. You’re far better off setting up a proper url within your hosts file
This will make session/cookies/oauth much easier
Thomas Sieverding
@Bajix
Aug 03 2016 19:17
Update using: sudo nano /etc/hosts. Add something like 127.0.0.1 dev.mydomain.com
You should totally make your url config driven as well
In package.json’s system prop:
"envs": {
  "development": {
    "map": {
      "config": "./assets/config/development.json"
    }
  },
  "production": {
    "map": {
      "config": "./assets/config/production.json"
    }
  },
  "staging": {
    "map": {
      "config": "./assets/config/staging.json"
    }
  }
},
Gerard Finnerty
@halcyonandon
Aug 03 2016 22:14
Everything I've been reading says can-value is deprecated, but https://canjs.com/docs/can.view.bindings.can-value-checkbox.html still says to use it. Is the checkbox doc just out-of-date or should we still be using can-value for checkboxes?
Thomas Sieverding
@Bajix
Aug 03 2016 22:15
@halcyonandon Use ($checked)=“myBool"
Gerard Finnerty
@halcyonandon
Aug 03 2016 22:17
@Bajix Thanks Thomas. Previously, we were able to set the checked true and false values to non-bool values. Do you know if this is possible with the new binding syntax? can-value='sex' can-true-value='male' can-false-value='female'
Mason Shin
@minsooshin
Aug 03 2016 22:18
@halcyonandon I also have same question :)
<input type="checkbox" id="agreement_check"
        can-value="isAgreed" can-true-value="true" can-false-value=“false”>
<input type=“checkbox” ($checked)=“isAgreed” >
is this the new binding syntax for it?
Thomas Sieverding
@Bajix
Aug 03 2016 22:21
Yes
You could probably use call expressions to do that
Mason Shin
@minsooshin
Aug 03 2016 22:21
how about @halcyonandon’s example? it has male for true, and female for false
call expressions?
Gerard Finnerty
@halcyonandon
Aug 03 2016 22:22
@minsooshin Yeah, same thing... I don't think that's the right syntax because isAgreed would need to be bool to set the checked state... or a method that returns bool checked AND sets the actual value for true or false
Thomas Sieverding
@Bajix
Aug 03 2016 22:23
Looking at the source code, maybe you could still do can-true-value/can-false-value
In conjunction w/ ($checked)
If that doesn’t work, use call expressions
Gerard Finnerty
@halcyonandon
Aug 03 2016 22:24
you can still do can-true-value, but it is also still deprecated syntax, so even though it works, I don't think it should be something adopted if you're also using the new bindings (please someone correct me if I'm wrong)
Gerard Finnerty
@halcyonandon
Aug 03 2016 22:32
@justinbmeyer any update love coming to the checkbox docs? :smile: https://canjs.com/docs/can.view.bindings.can-value-checkbox.html
Thomas Sieverding
@Bajix
Aug 03 2016 22:34
I’m a little bit confused by your use case. Why would you use a check box for things with discreet value sets?
Male / Female is more of a use case for select / radio inputs, not check boxes
Mason Shin
@minsooshin
Aug 03 2016 22:39
I think he just used the example from what CanJS website has
from the page he shared above.
because the document says it is deprecated, but still inform how to use out-dated syntax
Gerard Finnerty
@halcyonandon
Aug 03 2016 23:10

@Bajix If checked, the value of a checkbox can be non-bool and often is. Even in the vanilla markup examples... so while the checked attr is bool, the value won't be, so just guessing, but the new syntax calls for

<input type=“checkbox” (($checked))="someBool" (($value))="someString" />

...but the problem here is value and checked and disconnected
In canjs/canjs#2167 ...the open issue regarding this issue points back to a Gitter discussion https://gitter.im/canjs/canjs?at=5705487bb12cb51618d29c3d

so basically, can-value is deprecated, but not deprecated for radios and checkboxes yet