These are chat archives for skatejs/skatejs

11th
Aug 2016
Rob Hicks
@robhicks
Aug 11 2016 14:25
Hopefully, I have a simple question. I'm new to skatejs and web components in general. I want to pass in a config object through an attribute. So far I have done the following:
`skate.define('fs-civ-root', {
props: {
config: skate.prop.string({
attribute: true,
deserialize(val) {
try {
let tileSources = JSON.parse(val).tileSources;
console.log("tileSources", tileSources);
return tileSources;
} catch(e) {}
}
})
}
}
`
Is that the right way to do it? And, if so, how is the property accessible in skate? I have tried element.config but it is undefined.
Trey Shugart
@treshugart
Aug 11 2016 23:31
skate.define('fs-civ-root', {
  props: {
    config: skate.prop.string({
      attribute: true,
      deserialize(val) {
        try {
          let tileSources = JSON.parse(val).tileSources;
          console.log("tileSources", tileSources);
          return tileSources;
        } catch(e) {}
      }
    })
  }
}
just reformatting for posterity :)
That looks correct. Though, you’d probably want to serialize(), too.

The problem you might be having, @robhicks, is that the element may not be upgraded by the time you’re accessing it. You can try using skate.ready(element, callback) to do stuff when an element is upgraded, or you can try imperatively creating it with the constructor and then trying to access the property:

```js

woops
const elem = new FsCivRoot();
elem.config;
That assumes you’ve saved the return value of skate.define() in a const called FsCivRoot;