Giter VIP home page Giter VIP logo

Comments (4)

k-ode avatar k-ode commented on June 14, 2024 1

The custom loader you outlined does solve this, I just wanted to clarify our use case.

I had to change the argument to template to an array though.

ko.components.loaders.splice(1, 0, {
    getConfig(name, callback) {
        const isSUT = name === '_SUT'; // this is the name the tester uses to register components
        const emptyComponentConfig = { template: [document.createElement('div')] };
        callback(isSUT ? null : emptyComponentConfig);
    }
});

from ko-component-tester.

caseyWebb avatar caseyWebb commented on June 14, 2024

This is pretty much the default if you don't register the child components. If you want to block those registrations you can do it with a component loader.

ko.components.loaders.splice(1, 0, {
  getConfig(name, callback) {
    const isSUT = name === '_SUT' // this is the name the tester uses to register components
    const emptyComponentConfig = { template: document.createElement('div') }
    callback(isSUT ? null : emptyComponentConfig)
  }
})

We insert at the 2nd position in the array to preserve $.fn.getComponentParams which
uses a component loader itself to intercept the params. See here. Now you can go one step farther and assert your child components were passed the correct params.

const parent = {
  viewModel() { this.childText = 'foo' },
  template: '<child params="text: childText"></child>'
}

const $parent = renderComponent(parent)
const $child = $('child', $el)

$child.getComponentParams() === { text: 'foo' }

from ko-component-tester.

caseyWebb avatar caseyWebb commented on June 14, 2024

This could — and should — be incorporated into the api somehow.

from ko-component-tester.

k-ode avatar k-ode commented on June 14, 2024

Thanks for the clarification! That's very useful information.

However, I forgot to mention that we use the component-binding syntax for a lot for our sub components. And while it is true that custom elements are ignored if they are not registered, the component binding actually complains with Uncaught Error: Unknown component 'todo'.

We have to use the component binding sometimes because - unlike custom elements - it can be used as a virtual node. This is important if you use something like flexbox which doesn't work right with the extra dom elements that a custom element brings. It's also useful if you have to pass a lot arguments to a component, then you can just pass it as a object in the parent view model.

from ko-component-tester.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.