jdmcpeek / weB-ohnanza

Play Bohnanza, the international floral gaming sensation, online for free, forever.
0 stars 0 forks source link

Plots schema returns full object #13

Closed jdmcpeek closed 9 years ago

jdmcpeek commented 9 years ago

Working down the chain dependences. In plot.js:

var model = mongoose.model('Plot', schema); var example = new model(); console.log(example); // returns { _id: 54752a40ab970e658d4e336c, beans: [] }

All good.

jdmcpeek commented 9 years ago

In player.js:

var plot_model = require('./plot'); var plot_schema = plot_model.schema; var example = new plot_model(); console.log(example); // returns { _id: 54752be0c649cd898d1f261b, beans: [] }

All good.

jdmcpeek commented 9 years ago

'schema' variable could be leaking through module.exports

jdmcpeek commented 9 years ago

Test.js: where does Steven's donation go?

jdmcpeek commented 9 years ago

plot.js: plot_schema.methods.plant = function(beans){ for(var i=0; i<beans.length; i++){ this.beans.push(beans[i]); } };

What does 'this' describe here? The schema? Another thing: We pass the argument 'beans' into this fn, but what if 'beans' is actually a single object? For example, function donate_to_plot passes a single card into it.

jdmcpeek commented 9 years ago

Yup, function plant wasn't working because it expected an array and was getting a singular object.

jdmcpeek commented 9 years ago

We need to be sure we're passing the write data types into our methods.

jdmcpeek commented 9 years ago

Javascript gotcha: typeof Array === typeof Object // returns true.

Use Array.isArray to distinguish between objects and arrays.

Steven-Wright commented 9 years ago

@jdmcpeek - I'll try to be more explicit about what is expected from my methods. FYI if I use the plural of a single object I probably mean for it to be an array. Can you "overload" functions in javascript - not in the conventional way of course because javascript isn't "typed"?

so, now that we have the plot issue solved -> returning undefined because we weren't passing parameters properly.

but what is the deal with generate deck returning whatever a "full object" is?

Steven-Wright commented 9 years ago

check out the commit notes ee588f5000e9af82509d34eb4e76a63712c45e47. There's some weird behavior involving arrays happening...

Steven-Wright commented 9 years ago

can confirm - odd behavior does also affect player[i].plots but code remains functional.

Steven-Wright commented 9 years ago

@jdmcpeek - this was such a weird issue. I got it solved but best to check out the commit referenced in the PR.