New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is ractive.get supposed to return the original form of the data? #3112

Closed
fskreuz opened this Issue Oct 20, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@fskreuz
Contributor

fskreuz commented Oct 20, 2017

Description:

Instead of a long description, a picture paints a thousand words.

capture

The adaptor specifically tells Ractive to preserve the model when reset with a POJO on the adapted keypath. Therefore, a ractive.get() after a ractive.set with a POJO on the adapted keypath should return the Backbone model.

Expected:

  • ractive.get() returns the model (model1)
  • ractive.get() with unwrap: false returns the POJO representation (model2).
  • Adaptor would still work, updating in both directions.

Actual:

  • Both ractive.get() return the POJO after a ractive.set() (model3 and model4)
  • Adaptor still works on the same model.

Digging in, it seems that after the ractive.set(), the value (holds the POJO version) and wrapperValue (holds the original data) are now both holding the POJO value.

Versions affected:

0.7.3 and newer

Reproduction:

<script src="https://cdn.jsdelivr.net/npm/underscore@1/underscore.js"></script>
<script src="https://cdn.jsdelivr.net/npm/backbone@1/backbone.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ractive@0.9.5/ractive.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ractive-adaptors-backbone@0.3.0/dist/ractive-adaptors-backbone.min.js"></script>
const model = new Backbone.Model({ message: 'hello' })
const instance = Ractive({ adapt: [ 'Backbone' ], data: { model } })

debugger;
const model1 = instance.get('model')
const model2 = instance.get('model', { unwrap: false })
debugger;
instance.set('model', { message: 'world' })
debugger;
const model3 = instance.get('model')
const model4 = instance.get('model', { unwrap: false })
debugger;

t.strictEqual(instance.get('model'), model)
t.strictEqual(instance.get('model.message'), model.get('message'))

@fskreuz fskreuz changed the title from Adaptor replacing adapted data with POJO... even when I told it not to to Is ractive.get supposed to return the original form of the data? Oct 20, 2017

fskreuz added a commit that referenced this issue Oct 21, 2017

@evs-chris evs-chris closed this in 08420db Oct 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment