Search code examples
c#fluent-interface

JQuery Taconite C# helper


I'm writing a helper class to wrap the functionality of JQuery Taconite plugin. The plugin enables you to process multiple DOM updates in a single Ajax call.

The class simply enables you to construct the appropriate xml structure that is sent back to the client. I'm trying to wrap this functionality in a fluent interface. The basic example looks like this:

FluentTaconite ft = new FluentTaconite(writer);
ft
   .Select("#id1").ReplaceContentWith("Hello World!").FadeIn("100")
   .Select("#id2").AppendWith("<div>Another div</div>")
return ft.Output();

What I'm worried about is this, what structure would you expect be created after a call to this:

ft.Select("#A").AppendWith("<div id=B/>").AppendWith("div id=C/>")

Is your expectation to build:

<div id=A>
   <div id=B>
      <div id=C/>
    </div>
</div>

Or:

<div id=A>
   <div id=B/>
   <div id=C/>
</div>

The question is - are you expecting context to shift to a newly added content or remain at the selector?

Update The project in question is uploaded to code.google. Hope you find it useful.

Thanks for the input!


Solution

  • I expect it to remain at selector. Look at the following sample:

    ft.Select("#A").Append("<div id=B/>").Select("#B").Append("div id=C/>").End().Append("<br/>");
    

    I expect the following output:

    <div id='A'>
        <div id='B'>
            <div id='C'/></div>
        </div>
        <br/>
    </div>
    

    AppendWith imo is too noisy, it's enough of simple Append. 'End' method has similar functionality to JQuery's one.
    And I have one more question, are you sure that this will be more usable in comparison with javascript code?