Comments (12)
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.
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.
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.
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.
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.
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.
ok that does some/path/some/module/main
from knockout-amd-helpers.
so i have options scope for the module-loader-require, but not the template-loader-require.
from knockout-amd-helpers.
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.
@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.
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.
i'm looking into it, but templates resolve paths differently than amd-modules
from knockout-amd-helpers.
Related Issues (20)
- AfterRender not firing when module is initialized with a null observable HOT 2
- Getting the reference to the bound element HOT 10
- API available in bonded module needs to be called after template finishes rendering HOT 2
- Working with Typescript AMD Modules HOT 2
- [Request] Option to require additional files by convention HOT 1
- Provide simple way to load external templates from within custom bindings HOT 1
- afterRender still fires only for the first template when using external templates with requirejs/text HOT 2
- publish NuGet package for v.0.7.3 HOT 1
- Module Binding: require() for the template source should not have to wait until the module is downloaded
- Passing data from Tempate to Module HOT 2
- template binding with 'with' doesn't work HOT 4
- beforeRemove callback is not firing for template binding HOT 5
- Ready to use KO module using requirejs "map" HOT 2
- Passing markup into modules HOT 14
- Knockout-amd-helpers does not play well with r.js namespacing HOT 3
- renderTemplateSource produces an empty string HOT 3
- Dynamically assigning a template path in renderTemplate() HOT 2
- not working with webpack very well. HOT 2
- knockout-amd-helpers need new typings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout-amd-helpers.