Last active
November 6, 2017 16:30
-
-
Save VitorLuizC/b5794cd7650e875ddc41eb288824709c to your computer and use it in GitHub Desktop.
Shortly Vue
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 compose from './compose' | |
export default (watchers, method) => { | |
const shorlty = compose(watchers, | |
(_, watcher) => ({ | |
[watcher]: typeof method !== 'string' ? method : function () { | |
this[method](...arguments) | |
} | |
}) | |
) | |
return shortly | |
} |
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
/** | |
* @param {Object.<string, A>} object | |
* @param {function(string, A): Object.<string, B>} λ | |
* @template A, B | |
* @returns {Object.<string, B>} | |
*/ | |
export default (object, λ) => { | |
const entries = Object.entries(object) | |
const composition = entries.reduce( | |
(composition, [ property, value ]) => ({ | |
...composition, | |
...λ(property, value) || {} | |
}), | |
{} | |
) | |
return composition | |
} |
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
<template> | |
<form> | |
<fieldset> | |
<label for="input-name">Name</label> | |
<input v-model="user.name" id="input-name" /> | |
</fieldset> | |
<fieldset> | |
<label for="input-password">Password</label> | |
<input | |
v-model="user.password" | |
id="input-password" | |
type="password" | |
/> | |
</fieldset> | |
<blockquote v-if="error"> | |
<p>{{ error }}</p> | |
</blockquote> | |
</form> | |
</template> | |
<script> | |
import shortlyWatchers from 'vue-shortly-watchers' | |
export default { | |
data () { | |
return { | |
error: '', | |
user: { | |
name: '', | |
password: '' | |
} | |
} | |
}, | |
watch: shortlyWatchers(['user.name', 'user.password'], 'check'), | |
methods: { | |
check () { | |
this.error = (!this.user.name || !this.user.password) | |
? 'Empty name or password' | |
: '' | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment