Coder Social home page Coder Social logo

Comments (4)

rikschennink avatar rikschennink commented on May 10, 2024

It's used to create an easier way to apply a certain transform to a value.

This is the handler for the abs transform.

export default () => (value, cb) => cb(Math.abs(value));

This is the handler for the preset transform.

export default (...presets) => (value, cb, instance) => 
    cb(
        value.map(
            (v, index) => instance.getPreset(presets[index])(v, instance.getConstants(), instance)
        )
    );
  1. It receives all the defined presets in the transform (for example 'd', 'h', 'm', 's').
  2. Then in the order of the value array it'll get the preset for that value from the Tick instance preset array.

The value would be something like [0, 11, 3, 20] where 0 is days, 11 is hours, etc.

It'll thus load preset 'd' for 0, which is this preset:

d:(value, constants) => (
		transformDurationUnit(
			value,
			constants.DAY_SINGULAR,
			constants.DAY_PLURAL,
			365
		)
),

The value returned is passed on to the next node.

You can add your own presets with setPreset(key, value) and then you can use it in your tick template.

Honestly the preset/constant functions were only added to make creating date timers more easy. So that's kinda why they're not documented at this point.

from flip.

adas172002 avatar adas172002 commented on May 10, 2024

Thanks, it seems preset is specific to how flip is handling date timers. I was looking for documentation because example file is using preset(d, h, m, s) and for my project I just needed hour, minute and second. I removed d and it didn't work, so I tried to the docs and found nothing. Only after reading about option object format: ['h', 'm', 's'] I managed to make it work.

from flip.

rikschennink avatar rikschennink commented on May 10, 2024

@adas172002 Yes it maps directly to the format, so both should have the same keys.

from flip.

adas172002 avatar adas172002 commented on May 10, 2024

Great, I hope others will benefit from this information.

Closing the issue, thanks.

from flip.

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.