apeman-react-mixins
Version:
React mixin set of apeman.
43 lines (34 loc) • 729 B
JSX
/**
* Mixin for flush.
* @mixin ApFlushMixin
*/
import React, {PropTypes as types} from 'react'
import assert from 'assert'
/** @lends ApFlushMixin */
let ApFlushMixin = {
// --------------------
// Custom
// --------------------
$apFlushMixed: true,
/**
* Flush message.
* @param {string} msg - Message to show.
*/
flush (msg) {
if (!msg) {
return
}
const s = this
let [text, level] = msg.split(':').reverse()
s.toast(text, level)
},
// --------------------
// Lifecycle
// --------------------
componentWillMount () {
const s = this
assert.ok(s.$apToastMixed, 'ApToastMixin is required.')
}
}
export default Object.freeze(ApFlushMixin)