ampersand-dom-bindings icon indicating copy to clipboard operation
ampersand-dom-bindings copied to clipboard

Make bindings extensible

Open RickButler opened this issue 8 years ago • 2 comments

I opened this issue to discuss creating an extensible version of ampersand-dom-bindings, relating to AmpersandJS/ampersand-view#178 and #16.

RickButler avatar Jun 08 '16 20:06 RickButler

After doing some looking in other frameworks and seeing the old issue in AmpersandJS/ampersand-dom-bindings#16, and looking at how Backbone.Epoxy handles bindings. Most other frameworks use some variation of the creational design patterns to generate their bindings.

I will use Backbone.Epoxy as the example because it's the closest to ampersand being based on backbone.

They use Expoxy.binding as a proxy to a singleton 'bindinghandlers' that is locally scoped to Epoxy . You can globally add to the bindings with Epoxy.bindings or you can define bindings in your view. When a view is instantiated a clone of the binding singleton is made and the locally defined handlers are added to the clone.

So here is my suggestion for changes:

We can look at creating a singleton containing the bindings as a key function store and an API for accessing/extending them from in this project or a separate project. getBindingFunc would then be used to attempt to locate the binding in the singleton and apply the arguments passed to ampersand-dom-view to the binding function.

I would also like to look at the ability to pass in additional bindings as a parameter to ampersand-dom-bindings call. This would let you pass in locally defined bindings from the view. I will add a comment about this to AmpersandJS/ampersand-view#178.

RickButler avatar Jun 08 '16 21:06 RickButler

For anybody else that's looking for a solution right now, this works well:


var ContactInputView = InputView.extend({
	bindings: assign({}, {
		required: {
			type: 'booleanClass',
			name: 'is-required',
		},
	}, InputView.prototype.bindings),
	props: {
		containerEl: 'object',
	},
});

zeorin avatar Feb 25 '17 13:02 zeorin