-
Notifications
You must be signed in to change notification settings - Fork 48
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
Error when binding ember-mobiledoc-editor to a model #42
Comments
(Sorry, just a second on the S3-hosted app. I regenerated it as an Ember 1.13 app because that's what I've been working with primarily.) |
OK, the S3-hosted app should be available. I also took another look at the value of |
@chrisdpeters What version of Mobiledoc-Kit is being used in your demo? I added |
Also, Mobiledocs are an object not a string. |
Recreated with Mobiledoc-kit 0.7.3 and the repo locally. |
@chrisdpeters so the issue here is related to cursor position after an editor is destroyed. The usage you have (being bound to the body, and updating the body) causes the editor to be destroyed and recreated on every edit. Type a letter, and the To address this immediately, I suggest you create and "initial mobiledoc" property on the calling context and pass that as Basically, the editor component does not understand when you set a mobiledoc it just emitted as a change event. Steps to improve are:
|
Move the editor destroy/setup flow into willRender and didRender. Compare a new mobiledoc to the local mobiledoc and the upstream one before destroying and recreating the editor. Refs #42
Move the editor destroy/setup flow into willRender and didRender. Compare a new mobiledoc to the local mobiledoc and the upstream one before destroying and recreating the editor. Refs #42
@chrisdpeters Your demo is working correctly with a linked version of ember-mobiledoc-editor and mobiledoc-kit master. I'll cut a release in the next few days. |
@mixonic I appreciate this very much. I hope your update makes this addon even more useful for others! In the model, do you suggest that I change the
Instead of this?
Or does it matter now? |
@chrisdpeters Mobiledoc is a data structure, not a string. You may need some additional layer in your code to serialize the data into a string for saving, and then to restore it to an object when rendering. I recommend saving a JSON string and not data, but be aware that the |
OK, I have an import DS from 'ember-data';
export default DS.Transform.extend({
deserialize: function(serialized) {
if (typeof serialized === 'string') {
return JSON.parse(serialized);
}
else {
return serialized;
}
},
serialize: function(deserialized) {
return JSON.stringify(deserialized);
}
});
Do you think this is a worthwhile thing to add to the README, like all of this that we just explored? Or is all of this so fresh that it wouldn't be worthwhile? I'd be happy to do a pull request if you think it is worthwhile. |
@chrisdpeters I don't think we imply anywhere that Mobiledocs are strings. I'm open to documentation updates of course, though we probably don't need to talk about how to use Ember-Data in this project's README. |
I have an example app hosted on S3 that demonstrates the error that I've been experiencing:
http://mobiledoc-error.s3-website-us-east-1.amazonaws.com/
And here is the accompanying Git repo:
https://github.com/chrisdpeters/mobiledoc-error
I was following @mixonic's advice on how to bind the
{{mobiledoc-editor}}
mobiledoc
attribute to an Ember model attribute. We were discussing it in this gist.He had suggested that I do something like this:
With the component call setup like this, I get the following error on the 2nd keystroke within the editor:
If you run the S3-hosted app above, you'll see the state of the
article
record in Ember Inspector. It looks like it does get changed in some way but perhaps not howmobiledoc-editor
expects:Is there a different type that I should be setting the model attribute to? Right now, it's setup as a string:
Bonus issue: When I upgrade Ember and Ember Data to v2.2, I get the following console error on the very first keystroke:
Then I also get the error that the Ember 1.13 is tripping.
The text was updated successfully, but these errors were encountered: