nathanboktae / cherrytree-for-knockout

Use knockout components with CherryTree hiearchial routing
ISC License
4 stars 2 forks source link

Cherrytree for KO and RequireJS example #7

Open jsun-tech opened 8 years ago

jsun-tech commented 8 years ago

Hello Nathan,

I was trying to use cherrytree using require but I am having some problems. I was wondering if you could help me out.

the versions I am running are:

this is my main class

requirejs(['knockout', 'cherrytree', 'pages/home/home',
'components/greeting', 'cherrytree-for-knockout'], function (ko, cherrytree, homeComponent, greetingComponent, cherrytreefoko) {

    ko.components.register('home', homeComponent);
    ko.components.register('greeter', greetingComponent);

    router = cherrytree();

    router.map(function (route) {
        route('home', homeComponent);
    })

    router.use(ko.bindingHandlers.routeView.middleware);
    router.listen();

    ko.applyBindings({ router: router }, document.querySelector('main'));
});
<main data-bind="routeView: router"></main>

the problem that is on the console says: Uncaught (in promise) TypeError: Cannot read property 'name' of undefined(…) in this line: middlewareName = router.middleware[i].name || 'anonymous'; of cherrytree.js

It seems that I am not able to load the middleware.

Thanks a lot Nathan.

nathanboktae commented 8 years ago

We use requirejs with cherrytree-for-knockout, as well as bower, so we have a requirejs.config.js file that looks like this:

require.config({
  baseUrl: '/',
  paths: {
    cherrytree: 'bower_components/cherrytree/build/standalone',
    'cherrytree-for-knockout': 'bower_components/cherrytree-for-knockout/cherrytree-for-knockout',
    knockout: 'bower_components/knockout/dist/knockout.debug',
  }
})

so it's odd you are calling requirejs instead of require there (typo)? but cherrytree-for-knockout uses a UMD wrapper so you can easily use it as a regular script, or with require.js, webpack, browserify, and the like.