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

ccm-loading does not disappear #5

Closed
ghost opened this issue Jan 6, 2020 · 2 comments
Closed

ccm-loading does not disappear #5

ghost opened this issue Jan 6, 2020 · 2 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@ghost
Copy link

ghost commented Jan 6, 2020

In my component, the cc-loading indicator is visible all the time. This is my code:

(() => {
    const component = {
        name: 'counter-kh',
        ccm: 'https://ccmjs.github.io/ccm/ccm.js',
        config: {
            css: ['ccm.load', '']
        },
        Instance: function () {
            let clicks = 0;
            let count = 0;

            const countDisplay = document.createElement('p');
            const clicksDisplay = document.createElement('p');

            const incrementButton = document.createElement('button');
            const decrementButton = document.createElement('button');
            incrementButton.innerText = '+';
            decrementButton.innerText = '-';
            incrementButton.onclick = () => {clicks++; count++; this.update();};
            decrementButton.onclick = () => {clicks++; count--; this.update();};

            this.update = () => {
                countDisplay.innerText = `count: ${count}`;
                clicksDisplay.innerText = `clicks: ${clicks}`;
            };

            this.start = async () => {
                this.update();
                this.element.appendChild(countDisplay);
                this.element.appendChild(clicksDisplay);
                this.element.appendChild(incrementButton);
                this.element.appendChild(decrementButton);
            };
        }
    };
    let b = "ccm." + component.name + (component.version ? "-" + component.version.join(".") : "") + ".js"; if (window.ccm && null === window.ccm.files[b]) return window.ccm.files[b] = component; (b = window.ccm && window.ccm.components[component.name]) && b.ccm && (component.ccm = b.ccm); "string" === typeof component.ccm && (component.ccm = { url: component.ccm }); let c = (component.ccm.url.match(/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/) || ["latest"])[0]; if (window.ccm && window.ccm[c]) window.ccm[c].component(component); else { var a = document.createElement("script"); document.head.appendChild(a); component.ccm.integrity && a.setAttribute("integrity", component.ccm.integrity); component.ccm.crossorigin && a.setAttribute("crossorigin", component.ccm.crossorigin); a.onload = function () { window.ccm[c].component(component); document.head.removeChild(a) }; a.src = component.ccm.url }
})();

image

@akless
Copy link
Member

akless commented Jan 7, 2020

When the start method is called the first time, this.element only contains the loading icon. If you only append things to this.element, then the loading icon is never overwritten with other content. Before the first appendChild call you can do this.element.innerHTML = ''; to clear all content (that removes the loading icon).

@akless
Copy link
Member

akless commented Jan 7, 2020

Another hint: Your component name is counter-kh. A - is not allowed in a component name. Please avoid it. Maybe use a _ instead.

@akless akless self-assigned this Jan 7, 2020
@akless akless added the good first issue Good for newcomers label Jan 7, 2020
@ghost ghost closed this as completed Jan 8, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant