Render callback

This commit is contained in:
Josh Johnson 2016-07-02 11:11:16 +01:00
parent 2ffda7f8a1
commit ea7a7c2b22
3 changed files with 12 additions and 8 deletions

View file

@ -210,7 +210,7 @@ classNames: {
} }
``` ```
<strong>Usage:</strong> Classes added to HTML generated by Choices. <strong>Usage:</strong> Classes added to HTML generated by Choices. By default classnames follow the [BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/) notation.
### callbackOnInit ### callbackOnInit
<strong>Type:</strong> `Function` <strong>Default:</strong>`() => {}` <strong>Type:</strong> `Function` <strong>Default:</strong>`() => {}`

File diff suppressed because one or more lines are too long

View file

@ -40,7 +40,6 @@ export class Choices {
prependValue: null, prependValue: null,
appendValue: null, appendValue: null,
loadingText: 'Loading...', loadingText: 'Loading...',
logState: false,
classNames: { classNames: {
containerOuter: 'choices', containerOuter: 'choices',
containerInner: 'choices__inner', containerInner: 'choices__inner',
@ -69,6 +68,7 @@ export class Choices {
callbackOnInit: () => {}, callbackOnInit: () => {},
callbackOnAddItem: (id, value, passedInput) => {}, callbackOnAddItem: (id, value, passedInput) => {},
callbackOnRemoveItem: (id, value, passedInput) => {}, callbackOnRemoveItem: (id, value, passedInput) => {},
callbackOnRender: () => {},
}; };
// Merge options with user options // Merge options with user options
@ -1392,10 +1392,6 @@ export class Choices {
// Only render if our state has actually changed // Only render if our state has actually changed
if(this.currentState !== this.prevState) { if(this.currentState !== this.prevState) {
// Log state
if(this.config.logState) {
console.info(this.currentState);
}
// Choices // Choices
if((this.currentState.choices !== this.prevState.choices || this.currentState.groups !== this.prevState.groups)) { if((this.currentState.choices !== this.prevState.choices || this.currentState.groups !== this.prevState.groups)) {
@ -1447,6 +1443,14 @@ export class Choices {
} }
} }
if(callback = this.config.callbackOnRender){
if(isType('Function', callback)) {
callback();
} else {
console.error('callbackOnRender: Callback is not a function');
}
}
this.prevState = this.currentState; this.prevState = this.currentState;
} }
} }