Git Product home page Git Product logo

Comments (6)

vampirefan avatar vampirefan commented on June 27, 2024

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?

from meteor-sharejs.

mizzao avatar mizzao commented on June 27, 2024

I think this is a problem with how we can react to updated data in Blaze, similar to Meteor-Community-Packages/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?

from meteor-sharejs.

vampirefan avatar vampirefan commented on June 27, 2024

Here is my editor related code:

  • iron-router controller:
    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
      });
    });
  • editor template
    <template name="editor">
        {{> sharejsAce docid=docId callback=config id="editor"}}
    </template>
  • editor template helper
    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);
        }
      }
    });
  • my Posts collection has a property content stored markdown text.

from meteor-sharejs.

vampirefan avatar vampirefan commented on June 27, 2024

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.

from meteor-sharejs.

mizzao avatar mizzao commented on June 27, 2024

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?

from meteor-sharejs.

mizzao avatar mizzao commented on June 27, 2024

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.

from meteor-sharejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.