Comments (5)
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.
+1 on this. Classes namespacing may come handy when working with really generic APIs.
from ampersand-dom-bindings.
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.
+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.
Closing this as a duplicate of #13 - It will be resolved there.
from ampersand-dom-bindings.
Related Issues (20)
- Binding with innerHTML didn't fire script tag HOT 7
- Style properties HOT 8
- Borrow features from Backbone.Epoxy
- "falsy" values for attribute bindings act as true for certain attributes HOT 2
- Custom binding types HOT 5
- class binding should support an array of classes HOT 1
- new binding type: switchAttribute HOT 3
- Visibility binding types
- Changing a property bound to a checked property of a checkbox within an event handler can break.
- Add yes/no support to booleanAttribute HOT 1
- Should use amp-result HOT 2
- Update input value on blur
- pass binding context through to custom binding functions HOT 2
- Attribute `indeterminate` is not correctly toggled HOT 3
- Switch type assumes each cases value to be unique HOT 4
- class attribute via DOM binding to append itself to existing classes and not overwrite all HOT 1
- Only apply bindings if element is not currently focused
- Binding to a derived property does not update the DOM when the derived value changes HOT 11
- Make bindings extensible HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ampersand-dom-bindings.