Drawflow icon indicating copy to clipboard operation
Drawflow copied to clipboard

import fails when it doesn't include Home. and must spell exactly as `Home`

Open simkimsia opened this issue 3 years ago • 2 comments

I create this gist https://gist.github.com/simkimsia/2640f3a5b2753fc40450dba25d1c2ab6

In it i have 3 index files that are modified from your current docs/index.html. the differences between all 3 are:

  1. index-with-Home.html (this will have a Home in the import data)
  2. index-spell-home-still-fails.html (this uses home instead of Home and still cause failure)
  3. index-without-Home.html (this does not have Home at all and still fails)

Is there a way to import without being forced to include a Home at all?

simkimsia avatar Aug 07 '21 09:08 simkimsia

Hi @simkimsia

You can try this solution:

       editor.reroute = true;
        
        editor.import = function(data, notifi = true) {
            this.clear();
            this.drawflow = JSON.parse(JSON.stringify(data));
            if(notifi) {
                this.module= Object.keys(this.drawflow.drawflow)[0];
            }
            this.load();
            if(notifi) {
            this.dispatch('import', 'import');
            }
        }

        editor.start();

It would also be convenient to modify the function:

    editor.removeModule = function(name) {
            delete this.drawflow.drawflow[name];
            this.dispatch('moduleRemoved', name);

            if(this.module === name) {
                this.changeModule(Object.keys(this.drawflow.drawflow)[0]);
            }
        }

I will check so that this does not happen. Or you can define a module other than Home.

Jero

jerosoler avatar Aug 07 '21 11:08 jerosoler

Thank you for response @jerosoler

I am not fantastic at Javascript but i think your solution is basically suggesting that I override your original implementation of the two functions import and removeModule yes?

if so, this is good but temporary. because as time goes by, you will slowly add more code and may even modify these two methods or their signatures and so my override will eventually become wrong.

I think a long term solution would be your library consider the situation of users not starting with "Home" or removing modules midway in their usage into account. Do you agree? Let me know if I am mistaken in my thinking. Thank you.

simkimsia avatar Aug 08 '21 04:08 simkimsia