Giter Club home page Giter Club logo

Comments (5)

ckirkendall avatar ckirkendall commented on July 28, 2024

Not sure I can fix this. Defsnippet and Deftemplate return DocumentFragments(DF) objects. you can perform some actions on but not all. The DF object has to be added to the live dom to do all actions on it. I do this during creation of the fragment in the defsnippet but I have to detach it when I return it to you.

What type of logic are you having trouble integrating into a defsnippet. Can you give me more examples this logic. Below is an example of bundling the logic you show in your code example.

(em/deftemplate sn "..." [id]
    ["_TMP_ID"] (em/set-attr :id id))

or

(em/deftemplate sn "..." [id class]
    [class] (em/set-attr :id id))

from enfocus.

tonsky avatar tonsky commented on July 28, 2024

I'm trying to use some rich control structures, like this (pseudocode):

(em/deftemplate sn "..." [id]
  (let [style (f ...)
        smth (g ...)]
    (if (and x y)
      (transform ["_TMP_ID"] (em/set-attr :id id))
      identity)))

from enfocus.

ckirkendall avatar ckirkendall commented on July 28, 2024

@tonsky,
Transformations like this are best encapsulated in a custom transform. This allows you to have much more freedom in how you structure things and also allows you to use "at" inside a template. Below is some sample code.

(defn my-cust-trans [id]
   (em/trans [node] 
      (let [style (f ...)
            smth (g ...)]
          (if (and x y)
             (at node (em/set-attr :id id))
             (at node
                 [".class"] (em/...)
                 ["#id"] (em/....))
             node))))

(em/deftemplate sn "..." [id]
  ["#TOP_LEVEL_ID"]  (my-cust-trans id))

from enfocus.

tonsky avatar tonsky commented on July 28, 2024

@ckirkendall Thanks for advise, this will work great!

BTW, may be this may help: if you wrap documentFragment in div, it support most of usual document functions. Google Closure is doing something like this: http://closure-library.googlecode.com/svn/docs/closure_goog_dom_dom.js.source.html#line797

I've run quick test in webkit and it seems working for me:

var fragment = document.createDocumentFragment();
var div = document.createElement('div');
div.innerHTML = "abc <em>xyz</em> zer";
fragment.appendChild(div);
// fragment.getElementsByTagName('em'); // fails
fragment.childNodes[0].getElementsByTagName('em');

Maybe this is the way to go?

from enfocus.

ckirkendall avatar ckirkendall commented on July 28, 2024

@tonsky This is the method I use to allow you to manipulate the snippet during creation. I have to detach it to make sure what I hand back is the snippet and only the snippet. Another step you have to do to get all the methods is to attach it to the live dom. I do this also during creation.

from enfocus.

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.