Coder Social home page Coder Social logo

Comments (14)

rniemeyer avatar rniemeyer commented on July 28, 2024 1

@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.

rniemeyer avatar rniemeyer commented on July 28, 2024 1

@AmyAmy Sorry for the delay in getting this in. Thank-you for the idea/issue!

from knockout-amd-helpers.

AmyAmy avatar AmyAmy commented on July 28, 2024

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.

AmyAmy avatar AmyAmy commented on July 28, 2024

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.

rniemeyer avatar rniemeyer commented on July 28, 2024

@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.

AmyAmy avatar AmyAmy commented on July 28, 2024

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.

AmyAmy avatar AmyAmy commented on July 28, 2024

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.

rniemeyer avatar rniemeyer commented on July 28, 2024

@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.

AmyAmy avatar AmyAmy commented on July 28, 2024

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.

rniemeyer avatar rniemeyer commented on July 28, 2024

@AmyAmy - I like moveNodesToContext for a name!

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on July 28, 2024

@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.

AmyAmy avatar AmyAmy commented on July 28, 2024

@rniemeyer

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.

rniemeyer avatar rniemeyer commented on July 28, 2024

@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.

rniemeyer avatar rniemeyer commented on July 28, 2024

This has been implemented (finally) in the latest version (v1.0.0).

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.