JackAdams / meteor-editable-text

Drop-in editable text widget for meteor

Home Page:http://editable-text-demo.taonova.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expected plain object

JulianKingman opened this issue · comments

I'm getting an error when editing a field, which I suspect is related to the Astronomy package (https://github.com/jagi/meteor-astronomy), as it changes the collection into a class, possibly? I'm not really sure, let me know if you have any ideas.

Exception while simulating the effect of invoking '_editableTextWrite' M…r.m…e.errorClass {message: "Match error: Expected plain object", path: "", sanitizedError: M…r.m…e.errorClass, errorType: "Match.Error"} Error: Match error: Expected plain object at checkSubtree (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:314:11) at check (http://localhost:3000/packages/check.js?ac81167b8513b85b926c167bba423981b0c4cf9c:67:5) at Meteor.methods._editableTextWrite (http://localhost:3000/packages/babrahams_editable-text.js?187254c172a9dfe0c1a79510d9302ede8f2ac602:850:96) at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4269:25 at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17) at _.extend.apply (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4260:54) at _.extend.call (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4138:17) at Object.EditableText.update (http://localhost:3000/packages/babrahams_editable-text.js?187254c172a9dfe0c1a79510d9302ede8f2ac602:338:12) at Object.EditableText._makeUpdate (http://localhost:3000/packages/babrahams_editable-text.js?187254c172a9dfe0c1a79510d9302ede8f2ac602:511:27) at Object.EditableText.okCancelEvents.ok (http://localhost:3000/packages/babrahams_editable-text.js?187254c172a9dfe0c1a79510d9302ede8f2ac602:611:28)

Yep. That's astronomy applying its schema to the writes done by this package. I've got support for aldeed:collection2 by default but haven't rolled in support for jagi:astronomy yet. Not much that can be done at the moment, but I'll take a look at it as soon as I get a chance.

@JackAdams Anything I can do to help?

If you want to take a look at the code and put a PR together with astronomy support, I'd be more than happy to merge it. The relevant part of the codebase is here.

No, wait a minute. Just checking over the error in that stack trace again -- it might not be astronomy applying its schema -- it might be doing a transform which is causing the match error. Any chance you could put a minimal repro up on meteorpad? That would help me get to the root of the problem pretty quickly.

Funny, I'm having a hard time replicating the problem, I'll let you know when I've got the problem figured out, which may end up being the same time I solve the probelm :)

Try to set EditableText.useMethods=false.

Thanks! Does that go right in the spacebars tag? If so, it didn't work.

No that goes in regular JS code that is common to client and server. But I don't recommend using EditableText.useMethods=false unless you've got a really tight set of allow/deny rules.

OK, I'm not sure what I changed, but the meteorpad is showing the error now: http://app-fmkjw53h.meteorpad.com/

That url for meteorpad above is a temporary link for the app instance, only lasting as long as the instance is alive (and because they're shut down fairly aggressively by Meteorpad to save resources, it's gone already). The link I need is one from the browser address bar while editing the Meteor pad, not the one from the little window where the app instance is shown.

Just tested in Firefox and Chrome, but I'm not getting the error described above. Everything seems to be working fine.

This is the set of packages and versions that's working for me:

.meteor/packages
autopublish
insecure
meteor-platform
jagi:astronomy
babrahams:editable-text
kadira:flow-router
kadira:blaze-layout

.meteor/versions
autopublish@1.0.3
autoupdate@1.2.1
babrahams:editable-text@0.8.2
base64@1.0.3
binary-heap@1.0.3
blaze@2.1.2
blaze-tools@1.0.3
boilerplate-generator@1.0.3
callback-hook@1.0.3
check@1.0.5
coffeescript@1.0.6
cosmos:browserify@0.5.0
dburles:mongo-collection-instances@0.3.4
ddp@1.1.0
deps@1.0.7
djedi:sanitize-html@1.9.0
ejson@1.0.6
fastclick@1.0.3
geojson-utils@1.0.3
gwendall:body-events@0.1.6
html-tools@1.0.4
htmljs@1.0.4
http@1.1.0
id-map@1.0.3
insecure@1.0.3
jagi:astronomy@0.1.0
jquery@1.11.3_2
json@1.0.3
kadira:blaze-layout@2.1.0
kadira:flow-router@2.6.0
lai:collection-extensions@0.1.4
launch-screen@1.0.2
livedata@1.0.13
logging@1.0.7
meteor@1.1.6
meteor-platform@1.2.2
minifiers@1.1.5
minimongo@1.0.8
mobile-status-bar@1.0.3
mongo@1.1.0
observe-sequence@1.0.6
ordered-dict@1.0.3
random@1.0.3
reactive-dict@1.1.0
reactive-var@1.0.5
reload@1.1.3
retry@1.0.3
routepolicy@1.0.5
session@1.1.0
spacebars@1.0.6
spacebars-compiler@1.0.6
templating@1.1.1
tracker@1.0.7
ui@1.0.6
underscore@1.0.3
url@1.0.4
webapp@1.2.0
webapp-hashing@1.0.3

Wow, sorry about that! Very strange... Anyway, I added the Astronomy-relations module, it seems to be what's breaking it, try again.

Okay jagi:astronomy-relations messes pretty fundamentally with the data returned with findOne. I'm kind of surprised that the correct text even shows at all for those editable fields. To work around this, give an explicit context:

<h1>{{> editableText collection="sources" context=_original field="title"}}</h1>
<div>{{> editableText collection="sources" context=_original field="edition"}}</div>

In doing so, you'll probably lose any related updates that the relations packages is supposed to maintain.

That does the trick, thank you! What does '_original' context mean?

I'll point out the issue on the astronomy relations module, as well.

That's not an issue with astronomy - it's just the way the package manages relations between collections. The usual data that would be returned by a findOne is returned under the param _original.

Sent from my iPhone

On Sep 12, 2015, at 8:42 PM, JulianKingman notifications@github.com wrote:

That does the trick, thank you! What does '_original' context mean?

I'll point out the issue on the astronomy relations module, as well.


Reply to this email directly or view it on GitHub.

I've been working with Jagi (author of astronomy) to see how to best address the issue, here were his comments:

Ok I've investigated the editableText package and the problem is on their side. They assume that object >passed to the editableText helper is a plain JavaScript object but it's not. This assumption is wrong.

However, you can overcome this inconvenience and do something like this:

{{#with source.get()}}
 <h1>{{> editableText collection="sources" field="title"}}</h1>
 <div>{{> editableText collection="sources" field="edition"}}</div>
 <h4>{{_id}}</h4>
{{/with}}

As you can see instead the source context I've used source.get() which gets plain JavaScript object.

There's no real assumption, incorrect or otherwise, being made about the context by the editable-text package -- the context has to be correct already or set explicitly -- that's just how it works. Like the docs say:

Note: The widget assumes that the data context is that of a single document from the posts collection (with the _id value included).

You can also set the data context explicitly as follows:

{{> editableText context=singlePostDocument collection="posts" field="author"}}

I guess I could point out that the singlePostDocument of the context should be a plain javascript object but, for documents from the db, that should already be the case (unless funky transforms have been applied).

I'm getting this issue again, but this time the context doesn't seem to help. I'm guessing this has to do with this:

var self = _.clone(this);

Is that right? If so, ES2015 has a new way of copying objects:

var self = Object.assign({}, this);

I could submit a PR to implement that. For compatibility, we'd either need to depend on ecmascript or use a polyfill (e.g. here: http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object)

Looks like jQuery handles it too:

var self = $.extend(true, {}, this);

I'm interested in getting this working well with Astronomy, what is the purpose of this, and is there a way to make it more flexible to accept astronomy objects? I think it will just 'work', without this check, but I'm not sure of the consequences.

    check(data.context,(typeof FS !== "undefined" && FS.File) ? Match.OneOf(Object, FS.File) : Object);