Comments (14)
@AmyAmy - Let me look into this a little bit and see what makes the most sense. Also, so I understand the context, can you explain the reason that you need the original nodes? Thanks!
from knockout-amd-helpers.
@AmyAmy Sorry for the delay in getting this in. Thank-you for the idea/issue!
from knockout-amd-helpers.
Ok, actually, I think I have something that works:
when I add
var originalChildNodes = ko.utils.makeArray(ko.virtualElements.childNodes(element));
in ko.bindingHandlers.module.init
and then add $moduleTemplateNodes: originalChildNodes
to the context.extend
I get something that seems to work, Can't say anything about what sideeffects that would have, but I could make that into a pull request if you'd like.
Any clue if that would be a good approach?
from knockout-amd-helpers.
sure, to way oversimplify things: i'm working on a wysiwyg-like editor, in which modules can be nested into eachother in arbitrary ways.
so there could module which has conditions (checkboxes) which toggle the visibility of the contents of the module (which in turn could contain other modules).
Currently i'm using components, but I would prefer using your modules. (the code above I just copied from the knockout-components source)
from knockout-amd-helpers.
@AmyAmy - I looked at this a bit tonight. I think it would be okay to add this functionality into the library. I would like to make sure that this satisfies your scenario though: what do you end up doing with $moduleTemplateNodes
in this case? Do you have a custom binding that looks for the nodes and puts them back in place or something else? Would like to make sure that is not a better/nicer option that would make it easier to work with the nodes.
If you are interested in doing a pull request with these changes, let me know. Otherwise, I can get the changes in there as well. No worries either way.
from knockout-amd-helpers.
Usually I reuse them by having a
<!-- ko template: { nodes: $moduleTemplateNodes, data: $data } --><!-- /ko -->
somewhere inside the template.
The thing I'm worried most for is there could be additional knockout bindings inside the $moduleTemplateNodes, which should bind correctly. Even if there is, say, a <!-- ko if: [...] -->
or a <!-- ko foreach: [...] -->
surrounding the template-binding which is inserting the original nodes.
Hope that makes any sense. I'll try to make time to build some simple test-cases later today.
from knockout-amd-helpers.
https://gist.github.com/AmyAmy/1e06a8bb6142c625857bea6ab4895e75
I did run into one issue: had to disable the isAnonymous
check, not sure what can be done about this.
from knockout-amd-helpers.
@AmyAmy - seems like maybe the module binding should support an option (not quite sure what to call it) that would specifically grab the child nodes, put them on the context, and remove them prior to the isAnonymous
check.
from knockout-amd-helpers.
yeah that seems like the best approach. if only naming things wasn't so hard... :)
perhaps a moveNodesToContext: true
or something like that?
from knockout-amd-helpers.
@AmyAmy - I like moveNodesToContext
for a name!
from knockout-amd-helpers.
@AmyAmy - I implemented this option in this branch: https://github.com/rniemeyer/knockout-amd-helpers/tree/feature-allow-child-nodes. Perhaps you could grab the library from the build
directory of that branch and give it a shot. If all is well, then I will finish it up with tests and get it in the library.
from knockout-amd-helpers.
I Have been testing and working with the new build all day yesterday and today. haven't found any issues! :)
Thanks so much for putting this in. I would have wanted to do a pull request to save you the trouble, but I was struggling with getting the build env set up and such :(
from knockout-amd-helpers.
@AmyAmy - sorry that you had trouble with the build environment. It is a bit outdated at this point. I may revamp it one of these days :). I would be happy to help you get it going, if you should need to in the future.
I'll pursue getting this change in and tested to a released version. Glad it is working for you. It is a really interesting/useful feature for sure.
from knockout-amd-helpers.
This has been implemented (finally) in the latest version (v1.0.0).
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
- module and template loaders don't work with require.config moduleIDs packages HOT 12
- 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
- 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.