FiguredLimited/vue-mc

Models don't emit the "create" event on creation

tosty33 opened this issue · 5 comments

Models don't emit the "create" event on creation

A quick fix I applied on Model.js which will look into whether or not the saved version has an id:

onSaveSuccess(response) {

        // Find if it's a create or update action
        let action = 'create';
        if (this.saved('id')) {
           action = 'update'
        }

        // Clear errors because the request was successful.
        this.clearErrors();

        // Update this model with the data that was returned in the response.
        if (response) {
            this.update(response.getData());
        }

        Vue.set(this, 'saving', false);
        Vue.set(this, 'fatal',  false);

        // Automatically add to all registered collections.
        this.addToAllCollections();

        this.emit('save', {error: null});
        this.emit(action, {error: null});
    }

Also, it should emit save.success, not save. I am implementing the code in one large-ish scale project and I will generate pull requests with proper fixes for more issues I'm running into.

@sergiuwd could you please submit a PR for that? Looks good to me.

@rtheunissen submitting a PR with more fixes.

I believe this has now been fixed, as part of v0.6.0.