Skip to content

Instantly share code, notes, and snippets.

@bas080
Created May 11, 2016 02:57
Show Gist options
  • Save bas080/e02c9674e1a534c1e3ba01a11ecf296c to your computer and use it in GitHub Desktop.
Save bas080/e02c9674e1a534c1e3ba01a11ecf296c to your computer and use it in GitHub Desktop.
class FormElementGeneratedCustomElement {
@bindable entity;
@bindable property;
constructor(config) => {
this.entity = config.entityStrategy(this.entity);
this.validations = [];
let proxy = new Proxy(this.entity, function(entity, property){
if (config.translationStrategie.length 2) {
this.validations = config.validationStrategie(entity, property);
} else {
this.validation= = config.validationStrategie(entity);
}
return entity[name];
});
}
}
// Maybe let it be a multimethod style implementation
// Could also add a entity strategy to the config
// Maybe also add an entityStrategie that works with promises
config.entityStrategy = entityStrategies.aureliaOrm;
// a simple function that does translation
config.translationStrategie = bla.translate //some awesome translation lib's translate function
// important is to make sure the ormEntity is normalized to be able to
// commicate with views and other parts of the app. That way form elements can
// be reused
// BASICLY: maps the objects of the strategie to the properties used in the
// viewModel of the form-element component
function aureliaOrm(ormEntity) {
return proxy = new Proxy(ormEntity, (target, name) => {
const map = {
property: 'name',
};
return target[map[name]]
});
}
// the same function used in
//import {validate}
// property is also passed to enable per property validation. When property
// argument is not defined it will validation on the whole entity. Handy for
// when you only want validation to be performed on submit
config.validationStrategie = (entity, property) => {
return {
isValid: ,
message:
};
new FormValidator('temp')
};
config.renderStrategie = config.renderStrategies.bootstrap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment