mizzao / meteor-sharejs

Meteor smart package for transparently adding ShareJS editors to an app
MIT License
225 stars 53 forks source link

always display loading... in the editor #16

Closed vampirefan closed 10 years ago

vampirefan commented 10 years ago

[Error] open@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:157:27630 http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:157:27370 emit@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:157:1368 setState@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:157:26404 onopen@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:157:13628 e@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:133:52 channelOpened@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:133:216 Rb@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:123:146 nd@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:101:252 md@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:96:297 ec@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:94:485 Bc@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:93:311 yc@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:80:386 dispatchEvent@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:79:353 Rc@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:87:190 uc@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:86:402 Qb@http://localhost:3000/packages/sharejs.js?60558bce27a82a9deeefcde0e812d180e4364ab0:86:379 [native code] e (sharejs.js, line 133) channelOpened (sharejs.js, line 133) Rb (sharejs.js, line 123) nd (sharejs.js, line 101) md (sharejs.js, line 96) ec (sharejs.js, line 94) Bc (sharejs.js, line 93) yc (sharejs.js, line 80) dispatchEvent (sharejs.js, line 79) Rc (sharejs.js, line 87) uc (sharejs.js, line 86) Qb (sharejs.js, line 86) (anonymous function)


[Error] TypeError: 'null' is not an object (evaluating 'this.zb.n') Sb (sharejs.js, line 119) (anonymous function) (anonymous function) (sharejs.js, line 130)

vampirefan commented 10 years ago

I get it work by give a docID from template helper. the problem is that i want to set its init content instead of session value.

    Template['editor'].helpers({
      docId: function () {
        return this._id;
      },
      config: function () {
        var content = this.content;
        return function (editor) {
          // ace.setTheme('ace/theme/monokai');
          editor.setShowPrintMargin(false);
          editor.getSession().setUseWrapMode(true);
          editor.setValue(content);
          console.log(editor);
          console.log(content);
        }
      }
    });

Content is loaded right, but just a second, it disappeared and overwrited by content the last time I edited.

So may be I can edit the content from the document collection or something?

mizzao commented 10 years ago

I think this is a problem with how we can react to updated data in Blaze, similar to mizzao/meteor-autocomplete#30. The current system is a bit of a hack until the Blaze Component API is finalized. You are probably not using the helper as recommended, hence the bug. I'm not planning to completely fix this until an API for components is better defined.

Can you please provide the templates that you are using to load the editor? At least, you should try loading the package the way that the demo does it.

You may also be talking about the ShareJS option to replace a document's data when connecting. We don't really support that right now because the editor is initialized along with the open command.

Can you also please verify that you are on the latest version?

vampirefan commented 10 years ago

Here is my editor related code:

    var EditorController = RouteController.extend({
      template: 'editor',
      data: function () {
        return Posts.findOne(this.params._id); 
      }
    });

    Router.map(function () {
      this.route('home', {
        path: '/home',
        controller: HomeController
      });

      this.route('editor', {
        path: '/home/editor/:_id',
        controller: EditorController
      });
    });
    <template name="editor">
        {{> sharejsAce docid=docId callback=config id="editor"}}
    </template>
    Template['editor'].helpers({
      docId: function () {
        return this._id;
      },
      config: function () {
        var content = this.content;
        return function (editor) {
          // ace.setTheme('ace/theme/monokai');
          editor.setShowPrintMargin(false);
          editor.getSession().setUseWrapMode(true);
          editor.setValue(content);
          console.log(editor);
          console.log(content);
        }
      }
    });
vampirefan commented 10 years ago

When the editor refill its value from cache, it outputs the following line in the terminal:

I20140613-14:38:39.071(8)? Catchup X4pi9bCmWGQS5RDMn 0 -> 8

I just want to overwrite its init value, not from cache, but programmable initialize it.

mizzao commented 10 years ago

I can't tell from your description whether this is a UI issue that's causing the editor to be hooked up to the wrong document, or a feature request that is unsupported.

If you connect to a document with a certain name, you will get the contents of that document. That is what you are seeing with the Catchup ... stuff as ShareJS is sending over the operations. If you want to "overwrite" the contents of the document, you can either replace it with something else, or just create a new empty document and write in the contents. What is it exactly that you are trying to do?

mizzao commented 10 years ago

Closing due to lack of response from @vampirefan.

In order to change the contents of documents, you will have to submit operations to the ShareJS server from either server or client code. Simply changing the value of the editor won't cut it. There are also some other options such as opening the ShareJS operation with the replace option.

If you explain your use case better, I could provide some other suggestions. I have a feeling it's not necessary to do what you are doing now.