-
Notifications
You must be signed in to change notification settings - Fork 30
use scripttag or element id to fetch template and compile it #232
Comments
Hmm - only concern about implementing this sorta thing is that it's browser-specific - it wouldn't work so well on other platforms such as NodeJS. This could be built as a component however: <html>
<head>
</head>
<body paperclip>
<template name="blarg">
</template>
<!-- this doesn't work now, but it will in the future -->
<blarg />
<script type="text/javascript">
pc.templates = {};
function TemplateComponent() {
pc.Component.apply(this, arguments);
pc.components[this.attributes.name] = this;
}
// also make the template component global
pc.components.template = pc.Component.extend(TemplateComponent, {
update: function () {
if (this._rendered) return;
this._rendered = true;
this.section.appendChild(this.childTemplate.view({
parent: this.view
}));
}
});
</script>
<script type="text/javascript">
//paperclipify the entire web page
var source = document.body.innerHTML;
document.body.innerHTML = "";
document.body.appendChild(pc.template(source).view().render());
</script>
</body>
</html> |
Just a quick note to say a big thank you for all your answers and effort! Devmondo and I are working together on some projects and really fell in love with your project. So basically all his messages come from both of us, he's just doing all the talking for me as well :-) |
Haha, no problem. Definitely point out any un-obvious weird bits if you come across them! |
Thanks.. really appreciate this! It's a total pleasure to find such a kind and helpful developer.. |
this is awesome, man you are so helpful, and as @lan3jur said we just started on working on some project, and we have researched a lot, and your template syntax and personal attitude is what is making us fall in love with this :) hope you wont get bothered with the swarm of questions or bug reporting in future, i am really shocked this is not famous, i have researched like 1 week for databinding and templating stuff, and did not find this, i only found it by chance !!! |
Awesome - keep the questions coming. More questions = more docs for paperclip. It'll benefit anyone else who wants to use it. And yeah, It'd be awesome for paperclip to gain more traction as a template engine, but there's still quite a bit of noise - you got react, htmlbars (ember glimmer) ractive, and other new, hip reactive template engines. They're all fantastic options. |
we have tried them all, and Angular, but this is by far the cleanest and simplest i yet to come across, the one thing i am worried about though, is the use of dirty checking, is int angular criticized for this? could you elaborate on this and the comparison to object.observe performance ? |
Edited the last comment - broke the thread. Here are some additional thoughts: The key differentiator in paperclip is the interoperability. It's part of a "framework", but not in the traditional sense. I'm building out lots of little libraries that work well together - paperclip's just one of them. And the goal is to get everything to work with everything. I.e: paperclip should work with every framework, and every platform. And just in case you're curious, here are the other things that work nicely with paperclip: caplet - 11kb models library. Also works with react, angular, and other frameworks. Anyways, more stuff to come. So far we've got the |
Regarding the dirty type checking in angular - it's actually a pretty performant & simple approach. React does this with their dom-diffing. Paperclip has kind of a dirty type checking approach - it's all built into the accessor, and you can easily swap it out for something else. Adding support for |
thanks for the reply man, so in other words, paperclip is not slow on large data pages or eat memory or drain battery :) yea the accessors concept is amazing, did you check Polymer/observejs, |
The only real bottleneck is that templates are immutable, so if you're trying to do complex UI, then React, or some other virtual-dom library are probably better options. If what you're doing however is moving lots of elements around at the same time, then that's where paperclip really shines. You shouldn't have any performance issues - even on mobile devices. There are some also nifty mechanics within paperclip that'll speed up your application such as recycling views. Here's an old, outdated & broken benchmark suite: http://jsperf.com/pc-templating-comparison/2 Notice "paperclip recycle" - all that stuff is paperclip magic that happens behind the scenes. This is all thanks to the immutability of the engine. Also, here's another example: |
man, thanks a lot for the detailed answer, the benchmark look stunning, it is faster than react!! i am confused though what is the kind of app that has complex UI and will be slow with paperclip, do you mean for example Facebook, or real time stock data? because the DBMonster, is like outstanding performance, and there is a lot of data moving!!! i dont think any application we will make will have that amount of Data Display at once. and speaking of mobile, we are planning to create mobile App, is classdojo mobile app made with PaperClip if so this is amazing!!! so how you deal with datalists on mobile, as from what i read, it is the biggest issue on mobile when doing hybrid Apps |
I like this more and more each day :) |
in regards to caplet, have you seen Aurelia, the thing i like the most about it is that it is MVVM so your view is just normal html file with binding directives like paperclip and your view model is just ES6 class. i really really like this approach, no extend, no model and collection model like backbone or ember, you just bind to your class properties and methods, and the way view is bound to viewmodel is through router, i hope we can do the same with paperclip, as it will make syntax and work flow more concise :) |
oh yeah, the above template example, dont work is there a typo or it is just for illustration purposes :) |
hi again,
other libraries allow you to define templates in script tags or select an element by id or name and then bind the data to that element and in this case this wont be needed
so if we can do something like this
The text was updated successfully, but these errors were encountered: