Giter Club home page Giter Club logo

Comments (8)

rragan avatar rragan commented on June 8, 2024

This was posted in another issue recently.

dust.helpers.loop = function(chunk, context, bodies, params) {

var from = parseInt(dust.helpers.tap(params.from, chunk, context), 10) || 1,

    to = parseInt(dust.helpers.tap(params.to, chunk, context), 10) || 1,

    len = Math.abs(to - from) + 1,

    increment = (to - from) / (len - 1) || 1;

while(from !== to) {

  chunk = bodies.block(chunk, context.push(from, from, len));

  from += increment;

}

return chunk.render(bodies.block, context.push(from, from, len));

}

Used like

{@loop from=1 to="{end}"}This is iteration {.}{/loop}

{@loop from=10 to=0}Countdown T-{.}{/loop}

Sent from my iPad

On Nov 6, 2014, at 07:08, Luke Frake <[email protected]mailto:[email protected]> wrote:

I've started using dustjs for a project, and I need to be able to loop N times.

Is there a reason there isn't already a helper for this, as it seems like a basic piece of logic? The reason I'm asking is because I don't want to go against the core principles of dust.

If there is no reason, should I create a fork and a PR for a helper?

β€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/99.

from dustjs-helpers.

lukefrake avatar lukefrake commented on June 8, 2024

Great, thanks for that!

Should this be moved into the helpers if it's something that a few people want?

from dustjs-helpers.

sethkinast avatar sethkinast commented on June 8, 2024

That was my very quick untested code, and I suspect it has some bugs ;)

But I can look at polishing it up and asking if it's something that should be included.

I'm really not sure what the scope of dust-helpers is supposed to be. I have a bunch of these utility helpers (and I know others do too) that could expand the amount of functionality we provide.

from dustjs-helpers.

lukefrake avatar lukefrake commented on June 8, 2024

I've given it a quick test and it works perfectly for me! I won't promise there isn't a single bug ;)

I've got some helpers that I use on my project that I would merge in if people needed them. I don't know if there is a sensible way of gauging interest with helpers? Maybe just raising issues for helpers that we want/ have made, then if it gets enough +1's a fork can be created?

from dustjs-helpers.

sethkinast avatar sethkinast commented on June 8, 2024

I think that's totally reasonable!

I plan on rewriting the way helpers plug in to allow you to register new ones in a self-contained manner, so then you can provide helpers like you provide, say, Grunt plugins. That should make PRs easier.

from dustjs-helpers.

lukefrake avatar lukefrake commented on June 8, 2024

Sounds awesome, I'll keep an ear to the ground on this then πŸ‘

from dustjs-helpers.

rragan avatar rragan commented on June 8, 2024

Adding lots more helpers has come up before – dig through the closed issues. The problem is there are lots of individual needs but the 80/20 rules soon shows up and the low use helpers are many. The end result would be a very large dustjs-helpers library with attendant cost in the client environment.

In the end, I gave up and created dust-motes as a place to collect helpers of more than passing interest but not A-list helpers. After the initial push, it has languished but a couple of things like if and provide have become popular. I don’t take all PRs (e.g. no action on one that used eval heavily) but this could be a place for the less universally interesting ones.

http://rragan.github.io/dust-motes/

Rich

From: Seth Kinast [mailto:[email protected]]
Sent: Thursday, November 06, 2014 8:01 AM
To: linkedin/dustjs-helpers
Cc: Ragan, Richard
Subject: Re: [dustjs-helpers] Is there a reason why there is no loop helper? (#99)

That was my very quick untested code, and I suspect it has some bugs ;)

But I can look at polishing it up and asking if it's something that should be included.

I'm really not sure what the scope of dust-helpers is supposed to be. I have a bunch of these utility helpers (and I know others do too) that could expand the amount of functionality we provide.

β€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/99#issuecomment-62001125.

from dustjs-helpers.

lukefrake avatar lukefrake commented on June 8, 2024

Would having unused helpers have a detrimental affect one the end product. I mean the helpers would probably exist in the end product, but apart from that... Does dust get much slower per helper It has registered?

Maybe a customized package would be better. I only use about 4 of the helpers available in this repo for instance. So really I only need those four and the ones I've made.

My main concern is together we will right better code, so getting things on here would mean a better end product.

from dustjs-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.