Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: null is not an object (evaluating 'libraryController.importShareableObjectReference_intoDocument(this._object, this._documentData).localObject') #178

Closed
ivanortegaalba opened this issue Apr 20, 2018 · 8 comments

Comments

@ivanortegaalba
Copy link

ivanortegaalba commented Apr 20, 2018

Hi :)

I'm working with the new Library implementation in JS API. Working on Sketch 50 beta and the branch to introduce the compatibility on libraries. I have found this problem.

Running my code:

import api from './api';

export default function(context) {
    var document = api.getSelectedDocument();
    var libraries = api.getLibraries();

    libraries.forEach((library) => {
        const symbols = library.getImportableSymbolReferencesForDocument(document);

        symbols.forEach((symbol) => {
            symbol.import()
        });
    });
}

When I call import() I receive this error:

TypeError: null is not an object (evaluating 'libraryController.importShareableObjectReference_intoDocument(this._object, this._documentData).localObject')
line: 6251

And researching about the implementation this function importShareableObjectReference_intoDocument return null:

import() {
    if (!this._documentData) {
        throw new Error('missing document data');
    }
    const libraryController = AppController.sharedInstance().librariesController();
    console.log(
        'importedSymbol',
        libraryController.importShareableObjectReference_intoDocument(
            this._object,
            this._documentData
        ) // -> null
    );

    const importedSymbol = libraryController
    .importShareableObjectReference_intoDocument(this._object, this._documentData)
    .localObject();

    return wrapNativeObject(importedSymbol);
}

So, when we call .localObject() the error is thrown.

@mathieudutour
Copy link
Contributor

Yes indeed, the API changed in between. Thanks for spotting this.

Other than that, does the API make sense? Any rough edges?

@ivanortegaalba
Copy link
Author

ivanortegaalba commented Apr 20, 2018

For me it makes sense.

I'm trying to generate a document with all symbols from libraries. I'm trying to use this new API, and my approach is this:

import api from './api';

export default function(context) {
    var document = api.getSelectedDocument();
    var libraries = api.getLibraries(); // Something to select only the user libraries?

    libraries.forEach((library) => {
        const symbols = library.getImportableSymbolReferencesForDocument(document);

        symbols.forEach((symbol) => {
            const importedSymbol = symbol.import()
            // What would be your approach to have this symbols locally? 
            // We need to take in consideration that some symbols can reference other symbols as override or nestedSymbols. This is contemplated?
        });
    });
}

Thanks so much! :)

@ivanortegaalba
Copy link
Author

Also @mathieudutour, This is blocking for me, Would I have a workaround? Thanks!!!

@mathieudutour
Copy link
Contributor

What is “this”?

@mathieudutour
Copy link
Contributor

Also this bug only happens when trying to import a symbol that have already been imported

@ivanortegaalba
Copy link
Author

But this error is thrown when I call the import the first symbol.
Does it make sense that you receive a symbol already imported from the function getImportableSymbolReferencesForDocument ?

@mathieudutour
Copy link
Contributor

mathieudutour commented Apr 20, 2018 via email

@ivanortegaalba
Copy link
Author

Oh! Thank you @mathieudutour! Now, I have skipped the already imported symbols, because I have nested symbols inside other symbols.

Now we have the imported symbols in the document, but they still are linked to the library.
Is there a way through the API to unlink these symbols from the library? We are trying to consolidate multiple libraries into a single library, so we could distribute it easily ^^

captura de pantalla 2018-04-20 a las 15 41 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants