Forked from ykaragol/components.to-update-fields.js
Last active
March 22, 2017 11:35
-
-
Save feanor07/b720773fab1f595fa305dcba4870c2b6 to your computer and use it in GitHub Desktop.
Backtracking re-render strange behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const {isBlank, set, computed} = Ember; | |
export default Ember.Component.extend({ | |
errors:Ember.computed('address.city','address.street', function() { | |
let result = {}; | |
if (isBlank(this.get('address.street'))) { | |
set(result, 'street', 'Street cannot be empty'); | |
} | |
if (isBlank(this.get('address.city'))) { | |
set(result, 'city', 'City cannot be empty'); | |
} | |
this.get('onerrorraised')(result); | |
return result; | |
}), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
let ErrorDisplayer = Ember.Component.extend({ | |
}); | |
ErrorDisplayer.reopenClass({positionalParams: ['component', 'property']}); | |
export default ErrorDisplayer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const {isBlank, set, computed} = Ember; | |
export default Ember.Component.extend({ | |
errors:computed('person.name','person.surname', 'externalError', function() { | |
let result = {}; | |
if (isBlank(this.get('person.name'))) { | |
set(result, 'name', 'Name cannot be empty'); | |
} | |
if (isBlank(this.get('person.surname'))) { | |
set(result, 'surname', 'Surname cannot be empty'); | |
} | |
result = Ember.merge(result, this.get('externalError')); | |
this.get('onerrorraised')(result); | |
return result; | |
}), | |
actions: { | |
onexternalerrorraised(error) { | |
this.set('externalError', error); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
item: Ember.Object.create({address:{}}), | |
isValid:Ember.computed('errors', function(){ | |
return Object.keys(this.get('errors')).length === 0; | |
}), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export function errorFormatter(params/*, hash*/) { | |
let validatable = params[0]; | |
let property = params[1]; | |
return Ember.Object.create({ | |
validatable: validatable, | |
//error: Ember.computed.alias(`validatable.errors.${property}`) | |
errorBinding:`validatable.errors.${property}` | |
}); | |
} | |
export default Ember.Helper.helper(errorFormatter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment