Coder Social home page Coder Social logo

Comments (12)

rniemeyer avatar rniemeyer commented on July 28, 2024

I'll have to play with this type of setup. I would be eager to get a fix to make this work.

So, how does this behave if you set the baseDir and defaultPath to an empty string? That would, of course, mean that you need to specify the full path for everything.

I do see the point that you may want to use different methods for resolving the path and could certainly see the options passed to the binding used for that purpose.

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

i'm refactoring some code on a common library of ours, so there is the app-scope and lib-app-common-scope. Right now the defaultPath is set up to make the app-scope references easy, however the lib-app-common-scope becomes hard.

Currently setting it to '' may fallback to the requireConfig, but currently that would break other templates. I can try to refactor in that direction.

Right now I'm playing with the data-bind="modules:{ ... attribute to see if i can pass in an extra modifier to change the way moduleIDs work in the lib.

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on July 28, 2024

I think that supporting additional options would be a good direction to help with this issue and using an empty default baseDir/defaultPath being a workaround for now.

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on July 28, 2024

Just one other thing to mention, I have done some interesting things using the requirejs map functionality. For example, say my defaultPath in AMD-Helpers goes to myapp/one/two. I can set up a map like:

require.config({
    map: {
        "*": {
            "myapp/one/two/shared": "shared/modules",
        }
    }
});

What this means is that when you do module: 'shared/something', it will build a path of myapp/one/two/shared/something. The map config will cause this to actually be resolved to: shared/modules/something.

Just a way that you can link to other paths for the benefit of shorter syntax in the module binding.

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

I was thinking about that, but the generated moduleIDs i'm getting have some/path/.../.../.../some/module/main, or other variations that don't work.

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

i've even tried to do require.toUrl('some/module/name'), but i have not tried that in the actual template.....testing.

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

ok that does some/path/some/module/main

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

so i have options scope for the module-loader-require, but not the template-loader-require.

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

I have been working on a refactor based on the notion of the module and default paths == '' ( ex. ko.bindingHandlers.module.baseDir = '' and ko.amdTemplateEngine.defaultPath = ''), however, relative paths in the templates (in the case or modules or apps) have a weird context shift as they are loaded into the app, resulting in the paths breaking.

I'm trying some dynamic config stuff in the ModelView, but it seems like more work maybe than should be required.

It would be great if a template could reference another template relative to it's path like other require modules.

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on July 28, 2024

@jDavidnet - will have to think about the relative part. makes sense to me conceptually that you might want to define a base path at some level and allow modules/templates underneath it be specified relative to it. I don't have a clear thought on the best way to implement it though at the moment.

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

Yeah, @rniemeyer, I know. It's a tough one.

This is what i'm playing with now, but app then becomes still specific, and not relative to the app. Being that we are in a large javascript project we may want to load multiple apps/ modules. I think this can work if we can manage the name-spacing.

javascript
//in app.js
requirejs.config({
paths:{
// app: //Utils.getFilePath(require, '../')
// 'app.templates': require.toUrl('../templates')
'app.root': appRootPath,
'app.templates': Utils.getFilePath(require, '../templates'),
'app.view-models': Utils.getFilePath(require, './view-models'),
'app.constants': Utils.getFilePath(require, './constants')
}
});


``` javascript```
//in utils.js
/**
 * Get the file path relative to the current file.
 * @param requireContext RequireJS reference
 * @param relPath
 * @returns {string}
 */
getFilePath : function getFilePath (requireContext, relPath) {
    var path, pathArray;
    pathArray = requireContext.toUrl(relPath).split('/');
    pathArray.shift();
    return pathArray.join('/');
}

from knockout-amd-helpers.

jDavidnet avatar jDavidnet commented on July 28, 2024

i'm looking into it, but templates resolve paths differently than amd-modules

from knockout-amd-helpers.

Related Issues (20)

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.