Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Knockout extenders (client converters) #184

Merged
merged 13 commits into from Jun 7, 2016

Conversation

darilek
Copy link
Contributor

@darilek darilek commented May 17, 2016

Basic support for knockout extenders.
Steps to activate extender:

  1. decorate specified property with ClientExtenderAttribute
  2. create and register Knockout extender in javascript
  3. use extender when declare Knockout binding ie. data-bind='value: PropertyName.ExtenderName'

This patch is primarily intended for component developers (Knockout wrappers). It should be easy to expand support to the DotVVM binding syntax

@exyi
Copy link
Member

exyi commented May 17, 2016

Thank you, it seems to be pretty cool.
Maybe it may be useful to have more than one extender on a single property or to pass a parameter to the extender (not just true), so we can probably transfer the entire object in options like {myExtender1: "parameter value", anotherExtender: true} and the attribute should have a property for the parameter

I think we can merge it, @tomasherceg?

@darilek
Copy link
Contributor Author

darilek commented May 17, 2016

  • hardcoded parameter value is my mistake. I do not use parameters for now, but I agree, it shloud be supported
  • I did not tried apply more then one extender on observable property. But it is possible. Syntax is
this.propertyName = ko.observable(value).extend({ extender1 : param1, extender2 : param2})

@darilek
Copy link
Contributor Author

darilek commented May 18, 2016

I will try to prepare a patch which covers the points discussed above

@tomasherceg
Copy link
Member

Awesome. When it's ready, we can merge it and write some tests for this.

@darilek
Copy link
Contributor Author

darilek commented May 25, 2016

Hello, I've prepared second patch which covers @exyi requests :-)

Small example:

// C# view model class
public class ViewModel 
{
   // atribute has parameters: name, parameter value (optional) and order (optional)
   [ClientExtender("extender1", "hello world", 2]
   [ClientExtender("extender2", true, 1]
   public string PropertyName { get; set; }
}

Client side serialializer has ability chain declared extenders by specified order

// result of executed code on client side
this.PropertyName = ko.observable(value).extend({ extender2 : true}).extend({extender1 : "hello world"});

@darilek
Copy link
Contributor Author

darilek commented May 30, 2016

I've added the first (very simple) client extender sample - password strength indicator

@exyi exyi merged commit 5f3f3dc into riganti:master Jun 7, 2016
@exyi
Copy link
Member

exyi commented Jun 7, 2016

Sorry it took so long time, but finally merged. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants