George Pligoropoulos
George Pligoropoulos

Reputation: 2939

How to pass an object dynamically in the define function of Ext object in Sencha ExtJS 6.0.2?

Taking a look at the following segment of code you will see two cases where the sencha cmd return an error and one case that it doesn't

var memoryStore = new MemoryStore<Individual>("personnel", [
        'name', 'email', 'phone'
    ], [
        new Individual("Batman", "[email protected]", "+306969696969"),
        new Individual("Jean Luc", "[email protected]", "555-111-1111"),
        new Individual("Worf", "[email protected]", "+30 696 969 6969"),
        new Individual("Deanna", "[email protected]", "+30 6969696969"),
        new Individual("Data", "[email protected]", "+30-6969696969"),
    ])

    //memoryStore.toExtJS()

    Ext.define('extTestTs.store.Personnel', (function(){
        //return JSON.stringify(memoryStore.toExtJS())  //fails

        //return Ext.Object.merge({},{})    //fails

        return {} //succeeds
    })());

As you see we have removed everything, even extends is missing but as long as you are typing an object by hand it works. When this object is returned from a function it stops to work!

What does the sencha cmd does behind the scenes? Is it parsing the plain javascript as a text file?..
Because if it was javascript it would run without an issue.

This is the error from sencha cmd console output:

[ERR] C2008: Requirement had no matching files (extTestTs.store.Personnel) -- /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js:8:10 [ERR] [ERR] BUILD FAILED [ERR] com.sencha.exceptions.ExBuild: Failed to find any files for /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js::ClassRequire::extTestTs.store.Personnel [ERR] [ERR] Total time: 3 seconds [ERR] The following error occurred while executing this line: /home/student/bin/Sencha/Cmd/6.1.2.15/plugins/ext/current/plugin.xml:425: The following error occurred while executing this line: /home/student/Desktop/Typescript/extTestTs/.sencha/app/build-impl.xml:380: The following error occurred while executing this line: /home/student/Desktop/Typescript/extTestTs/.sencha/app/init-impl.xml:382: com.sencha.exceptions.ExBuild: Failed to find any files for /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js::ClassRequire::extTestTs.store.Personnel

How could we overcome this restriction of explicitly defining the object and rather define it more dynamically?

The goal is to make typescript work with ExtJS but not with the extreme unconventional solutions others propose, like forking typescript itself

Upvotes: 0

Views: 313

Answers (1)

George Pligoropoulos
George Pligoropoulos

Reputation: 2939

Found a workaround

First allow unreachable code in typescript

Here is a screenshot from the IntelliJ settings:

Screenshot from the IntelliJ settings

And the code in the questions transforms into that

var memoryStore = new MemoryStore<Individual>("personnel", [
        'name', 'email', 'phone'
    ], [
        new Individual("Batman", "[email protected]", "+306969696969"),
        new Individual("Jean Luc", "[email protected]", "555-111-1111"),
        new Individual("Worf", "[email protected]", "+30 696 969 6969"),
        new Individual("Deanna", "[email protected]", "+30 6969696969"),
        new Individual("Data", "[email protected]", "+30-6969696969"),
    ])

    //memoryStore.toExtJS()

    Ext.define('extTestTs.store.Personnel', function (Personnel) {
        return memoryStore.toExtJS()

        return {} //do not erase this line
    });

Yeah the line return {} might seem totally redundant but (obviously) the sencha cmd is trying to parse the file before it includes it in the requires

Now sencha cmd gives a success and executing sencha app web start the sample app works ok

Upvotes: 0

Related Questions