-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lodash and moment.js really necessary? #8
Comments
Hi! Thank you so much for using Vuex ORM! Vuex ORM uses lodash and moment but I too agree that it doesn't need complete lodash.js and moment.js. The reason why this is happening is because me lacking the knowledge of bundling TypeScript... Do you know any way to add only required functions from lodash or moment? Or would it make difference if I move those library to peer dependencies in package.json? |
Thanks for your reply. For lodash in ES6, you could just use The problem with moment.js is mainly, that it adds all localizations, even if you need only one. For your project, that might be necessary, since you need to support all languages as well, but i might ask, if you need that date-mutation at all, or if you could handle the developer such things? |
Ahah. That is easy. OK I'll do that.
You have good point. date-mutation is just "nice to have" feature and definitely not the must. I wasn't thinking so deeply about this but I agree that Vuex ORM should have little dependencies as possible. So, I'm thinking to add more general mutation feature and remove moment from this package. Something like below. import Model from 'vuex-orm/lib/Model'
import moment from 'moment'
class Post extends Model {
static entity = 'posts'
static fields () {
return {
// Pass callback to the attribute to mutate data.
published_at: this.attr('1985-10-10', value => moment(value))
}
}
// Or we could add such thing as a method separately...?
static mutations () {
return {
published_at (value) {
return moment(value)
}
}
}
} The above will do same as current So I'll first fix lodash issue and then remove moment from the project. Let me know if you have any advise on general mutator approach (the example of new API above). |
@CinKon Just wanted to let you know that I released v0.9.0 which includes breaking change on import syntax. From version 0.9.0, you must use following syntax. // Instead of these...
import Database from 'vuex-orm/lib/Database'
import Model from 'vuex-orm/lib/Model'
// Now you have to...
import { Database } from 'vuex-orm'
import { Model } from 'vuex-orm' Also you must call import VuexORM from 'vuex-orm'
store = new Vuex.Store({
plugin: [VuexORM.install(database)]
}) I've updated the docs as well. Sorry for the inconvenience. |
Please take care of your documentation ;) store = new Vuex.Store({
plugin: [VuexORM.install(database)]
}) This wont work. Either store = new Vuex.Store({
plugin: VuexORM.install(database)
}) Or store = new Vuex.Store({
plugins: [VuexORM.install(database)]
}) I found this inconsistency in your gitbook as well. |
But thanks for the update 👍 |
import { install as VuexORMInstall, Database } from 'vuex-orm'
const database = new Database()
database.register(User, user)
store = new Vuex.Store({
plugins: [VuexORMInstall(database)]
}) For completeness ;) With this, eslint goes crazy ( import VuexORM, { Database } from 'vuex-orm'
store = new Vuex.Store({
plugins: [VuexORM.install(database)]
}) |
Wow, thank you for the fix! (as always). I've updated the doc and published. |
OK, I've removed moment and introduced a new way to define mutator and released 0.10.0! You can find docs at https://revolver-app.gitbooks.io/vuex-orm/model/mutators.html. This has reduced the bundle size to about half before moment. I hope it helps reducing your project bundle size as well :) |
Thanks for your fast fixes! |
We just managed to integrate vuex-orm in our project, but had to determine that it adds ~1mb in vendor-files by adding complete lodash.js and moment.js.
Is this really necessary?
The text was updated successfully, but these errors were encountered: