substance / lens

Lens - open science content creation and display
http://substance.io/lens
MIT License
124 stars 20 forks source link

Overcome missing Node lifecycle hooks #71

Open michael opened 8 years ago

michael commented 8 years ago

I brought back adding of references and found some things broken as a result of the Node Api refactor. E.g. for bib items we relied on an initialization hook that parsed the source (json string) property and stored it as an object on a data field.

From BibItem.js:


  didInitialize: function() {
    // Only if citeproc
    if (this.format === "citeproc") {
      this.data = JSON.parse(this.source);
      this.guid = this.data.DOI || this.data.ISSN || this.id;
    } else {
      this.data = this.source;
      this.guid = this.id;
    }
  },

  // Note: we are updating the collection whenever
  // a BibItem is created so that we have its text compiled.
  // This is a different to Table or Figure collections
  // a compilation is done when the figure is shown or hidden
  // in the container.

  didAttach: function(doc) {
    if (!doc.isTransaction() && !doc.isClipboard()) {
      this.updateCollection(doc);
    }
  },

  didDetach: function(doc) {
    if (!doc.isTransaction() && !doc.isClipboard()) {
      this.updateCollection(doc);
    }
  },

This is has flaws in many ways.. for instance we used bibitem.guid as an index to be able to look up bibItems based on the DOI. Since this data is not explicitly set on construction it needed to be derived from source. If i understand correctly this indexing only worked because didInitialize was like a pre-creation hook.

I would suggest the following to fix it and also to simplify the implementation:

@oliver---- thoughts, objections?