Login Register

Is referencing storeItem._S to get the store reference bad?

Items get passed around a lot and normally I can pass the store around with them but in this case the item can't be accompanied by a store is it wrong to do the below?

constructor(item) 
{
    this.store = item._S; // NOTE: Is this bad???
    this.item = item;

    this.name = this.store.getValue(this.item, "name");
    etc
}

Can't Hurt (too bad)

It wouldn't be too bad, in my opinion to do something like this in your own code. Note, however, that by doing such a thing, you are not using "approved" data stores, and you lose a big benefit (probably *THE* big benefit) of using data stores in the first place - that you can swap one out in favor of another.

There is no guarantee that from one store to the next, the reference to the store will be _S.

However, as long as you are aware of those consequences...and you aren't planning on passing this code to anyone else who may or may not wonder why all of a sudden their widget doesn't work anymore...and you document it correctly, it should work as expected.