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

Can't render a Control Template. Rete enviroment with WebPack #256

Closed
limuyao opened this issue Feb 19, 2019 · 6 comments
Closed

Can't render a Control Template. Rete enviroment with WebPack #256

limuyao opened this issue Feb 19, 2019 · 6 comments

Comments

@limuyao
Copy link

limuyao commented Feb 19, 2019

Hi to all! The problem is on the picture (Rete can't render a Control template. There are not any <input> elements in the Number Nodes and in the Add Node)
1
I am using the code from the very first sample https://codepen.io/Ni55aN/pen/xzgQYq and a WebPack enviroment (configs and a full code below).
Btw, when i try to add console.log(this) for constructor of the NumControl i can see that "$el" of _vue is <!-- function(n,e,r,o){return ue(t,n,e,r,o,!0)} -->.
2

But it should be a vue object with a template <input type="number"...

3

What's wrong with me? And who can help me to solve the problem?

All of code here: https://github.com/limuyao/rete_env
WebPack config:

"use strict";
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    //entry: './src/index.js', //error [regeneratorRuntime is not defined]
    entry: ['babel-polyfill', './src/index.js'],
    output: {
        path: path.resolve(__dirname, '../dist'),
        filename: 'main.js'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.pug$/,
                loader: 'pug-plain-loader'
            },
            {
                test: /\.css$/,
                use: [
                    'vue-style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.sass$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    {
                        loader: 'sass-loader',
                        options: {
                            indentedSyntax: true
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin()
    ]
};
@Ni55aN
Copy link
Member

Ni55aN commented Feb 19, 2019

You need to update vue-render-plugin to latest version, because you have latest version of vue in your dependencies. For some reason vue@2.6.6 not compatible with version of vue that used by the render plugin (in previous versions)

@limuyao
Copy link
Author

limuyao commented Feb 19, 2019

Thank you for answer, Ni55aN, but i have updated the plugin and the problem remains =(

@Ni55aN
Copy link
Member

Ni55aN commented Feb 19, 2019

Is there any logs in the console?

@limuyao
Copy link
Author

limuyao commented Feb 20, 2019

there aren't any logs and errors in the console
And when i try to inspect the DOM structure of a node i can see that <div class='control'> has that the same text: <!-- function(n,e,r,o){return ue(t,n,e,r,o,!0)} -->

mb the reason is in the WebPack vue-loader that can't recognize that vue template?

@Ni55aN
Copy link
Member

Ni55aN commented Feb 20, 2019

vue-loader processes only a single file components.

Rather, you should have received the warning #249 (comment)
Therefore, Vue should to generate render() function based on template: retejs/examples#9 (comment)

But using vue-loader (with *.vue file) is more more preferred way

@limuyao
Copy link
Author

limuyao commented Feb 20, 2019

Thank you for answer, Ni55aN it helps me! I have solved the problem with the single file components:

  1. Create a file ../components/VueNumControlSingle.vue
<template>
    <input type="number" :readonly="readonly" :value="value" @input="change($event)" @dblclick.stop="" @pointermove.stop=""/>
</template>

<script>
    export default {
        props: ['readonly', 'emitter', 'ikey', 'getData', 'putData'],
        data() {
            return {
                value: 0,
            }
        },
        methods: {
            change(e){
                this.value = +e.target.value;
                this.update();
            },
            update() {
                if (this.ikey)
                    this.putData(this.ikey, this.value);
                this.emitter.trigger('process');
            }
        },
        mounted() {
            this.value = this.getData(this.ikey);
        }
    }
</script>

<style scoped>

</style>
  1. import it in index.js
import VueNumControlSingle from '../components/VueNumControlSingle.vue';
  1. And use it instead of VueNumControl in NumControl's constructor
class NumControl extends Rete.Control {

    constructor(emitter, key, readonly) {
        super(key);
        this.component = VueNumControlSingle; //instead of VueNumControl
        this.props = { emitter, ikey: key, readonly };
    }

    setValue(val) {
        this.vueContext.value = val;
    }
}

All of code is here: https://github.com/limuyao/rete_env

@limuyao limuyao closed this as completed Feb 20, 2019
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