stampit-org / stampit

OOP is better with stamps: Composable object factories.
https://stampit.js.org
MIT License
3.02k stars 102 forks source link

Overriding default properties from API example #322

Closed zarathustra323 closed 7 years ago

zarathustra323 commented 7 years ago

Good afternoon,

My apologies in advance if this ends up being a "stupid" question...

For whatever reason, the very simple example for stamp.props(...args) from the API docs doesn't appear to be working for me. The baffling thing is I've used stampit before and don't recall ever having this issue...

I have an index.js file that looks exactly like the example:

// index.js
const stampit = require('stampit');

const stamp = stampit().props({
  factor: 1
});

console.log(stamp().factor); // 1
console.log(stamp({factor: 5}).factor); // 5

When I run node index.js each log outputs 1, instead of 1 and 5 as expected:

stampit-test$ node index.js
1
1

I have a completely clean folder with nothing but index.js and stampit ^3.1.3 as the only dependency. I'm running node 6.11.2 (which is the latest LTS, or at least close) and npm 5.3.0.

Let me know your thoughts, of if I'm just completely crazy and/or doing something absolutely wrong. :)

koresar commented 7 years ago

Stamp is a new paradigm. It's natural to have issues. :)

Your code implies that you are using stampit v2. However, you are using v3. Basically, you hit the breaking change between v2 and v3.

See here: https://github.com/stampit-org/stampit/releases/tag/v3.0.0

The factory first argument properties are no longer automatically assigned to the instance.

You'll find there the change, and a workaround if really needed.

The good news is - there were no breaking changes for a year. Moreover, no breaking changes are expected in any foreseeable future. :)

Feel free to post any other questions. Cheers 👍

koresar commented 7 years ago

btw, fixing the docs now.