Code Monkey home page Code Monkey logo

Comments (9)

Munawwar avatar Munawwar commented on July 25, 2024

Question: Are there also bindings within your data-bind attribute that are exclusively for the client-side?

from htmlizer.

gustavnikolaj avatar gustavnikolaj commented on July 25, 2024

Yes. There probably will be. I'd prefer if htmlizer, when put in this mode, would just ignore bindings that it does not support.

var template = '<div data-bind="text: textContent, foo: bar"></div>';
var viewModel = { textContent: 'foobar' };
var output = (new HTMLizer(template).toString(viewModel);

The variable output should contain the following string:

<div data-bind="text: textContent, foo: bar">foobar</div>

This might be problematic as the bar value in the foo binding might trigger a ReferenceError when you evaluate the binding value. But this is the behaviour that I want...

from htmlizer.

gustavnikolaj avatar gustavnikolaj commented on July 25, 2024

If it prooves to be way to complex, I could live with having to write a transform function that took a template of

<div data-bind="text: textContent, foo: bar"></div>

and converted it into

<div data-htmlizer="text: textContent" data-bind="text: textContent, foo: bar"></div>

Essentially it's just a matter of duplicating the data-bind attribute and filtering the bindings down to the subset that htmlizer supports.

from htmlizer.

Munawwar avatar Munawwar commented on July 25, 2024

It is easy to ignore bindings that isn't supported.

What I was concerned is whether you provide data for all the supported bindings. If in your last example, textContent is undefined, then it would be more difficult to figure out when to ignore the binding and when to take undefined as a valid input. In KO and Htmlizer, null and undefined is valid input for the text binding (it just converts them to empty string). So hopefully that isn't part of your use case.

from htmlizer.

gustavnikolaj avatar gustavnikolaj commented on July 25, 2024

Anything rendered on the server should be discarded once it re-renders on the client.

The main caveat of that is that we will have to avoid anonymous templates.

If we have this template:

<div data-bind="text: textContent, foo: bar"></div>

I want htmlizer to turn it into:

<div data-bind="text: textContent, foo: bar">The value of textContent.</div>

And once I rerender on the client side, it will be reevaluated by knockout. In this case, it means that the text node The value of textContent will be replaced by whatever the client thinks is the value of textContent.

This is a bit wasteful, but it is about as good as it gets when we try to do server side rendering of a knockout application.

I hope that explains it.

from htmlizer.

Munawwar avatar Munawwar commented on July 25, 2024

@gustavnikolaj : Have a look whether the changes in the keepbindings branch satisfies your use case.

One more feature Htmlizer is missing at the moment is KO custom elements/components. Maybe you'd need that as well to write "isomorphic KO".

from htmlizer.

gustavnikolaj avatar gustavnikolaj commented on July 25, 2024

Thanks alot! I'll make sure to get back to you once I've tried it out :-)

from htmlizer.

gustavnikolaj avatar gustavnikolaj commented on July 25, 2024

@Munawwar LGTM! 👍

from htmlizer.

Munawwar avatar Munawwar commented on July 25, 2024

Merged and released v2.1.0.

from htmlizer.

Related Issues (18)

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.