Giter VIP home page Giter VIP logo

Comments (5)

legastero avatar legastero commented on June 19, 2024

Ah, I've had to deal with this situation before a few times. Creating derived properties on the view was what I ended up with:

    derived: {
        widgetStatus: {
            deps: ['model.status'],
            fn: function () {
                return 'widget-' + this.model.status;
            }
        }
    },
    bindings: {
        widgetStatus: {
            type: 'class'
        }
    }

from ampersand-dom-bindings.

kamilogorek avatar kamilogorek commented on June 19, 2024

+1 on this. Classes namespacing may come handy when working with really generic APIs.

from ampersand-dom-bindings.

jrmyio avatar jrmyio commented on June 19, 2024

Views can hold props/derived? I made a AmpersandJS/ampersandjs.com#81 on this undocumented feature.

However, I think the proposal still stands.

from ampersand-dom-bindings.

chesles avatar chesles commented on June 19, 2024

+1 on this -

Defining a derived property on the view is a decent workaround, but quite often there's something you want to do just to transform the value of the model's property before displaying it, whether it's prefixing a class, formatting a date or a number, etc. It's not ideal to have to define a bunch of formatted_[property] or prefixed_[property] properties that are just an extra layer between what is actually being rendered. It would be nice to define that function right there as part of the binding, as proposed here.

I think the option should be named something like format or transform instead of parse to make it clear what the function is meant to do: not necessarily parsing anything, but formatting or transforming the value for display.

from ampersand-dom-bindings.

pgilad avatar pgilad commented on June 19, 2024

Closing this as a duplicate of #13 - It will be resolved there.

from ampersand-dom-bindings.

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.