'use strict';

/**
 * FluxexObject is an object can be serialized and be constructed with the serialized status.
 * @class
 * @param {Object=} state - Serialized state
 */
var FluxexObject = function FluxexObject(state) {
    var copy = {};

    if ((state !== null) && ('object' === typeof state)) {
        this._context = state;
    } else {
        this._context = {};
    }
    
    if ('function' === typeof this.initialize) {
        Object.assign(copy, state);
        this.initialize();
        Object.assign(this._context, copy);
    }

};

Object.assign(FluxexObject.prototype,
/** @lends FluxexObject# */
{
    /**
     * Get a value or an object by name
     * @param {String} name - a simple key name
     * @return {Object|Number|String|Null} the value
     */
    _get: function (name) {
        return this._context[name];
    },

    /**
     * Restore the FluxexObject status by provided status object
     * @param {Object} state - the status to restore
     */
    _restore: function (state) {
        this._context = state;
    },

    /**
     * Set value by name
     * @param {String} name - a simple key name or json path
     * @return {FluxexObject} Self
     */
    _set: function (name, value) {
        this._context[name] = value;
        return this;
    },

    /**
     * Get serialized state
     * @return {String} A JSON string of current status
     */
    toString: function () {
        return JSON.stringify(this._context, function (K, V) {
            if (V === undefined) {
               console.warn('[Fluxex] undefined detected on key `' + K + '`! Please fix your store implementation to prevent store undefined into it, or you will see React client side error: `Invariant Violation: You\'re trying to render a component to the document using server rendering but the checksum was invalid.`');
            }
            return V;
        });
    }
});

module.exports = FluxexObject;

@@ -8,16 +8,624 @@
 rict';%0A%0A
+var stringify = function (V) %7B%0A    if ((typeof V === 'number') %7C%7C (typeof V === 'boolean') %7C%7C (V === undefined) %7C%7C (V === null)) %7B%0A        return V;%0A    %7D%0A%0A    if (V instanceof Date) %7B%0A        return 'new Date(' + V.toISOString() + ')';%0A    %7D%0A%0A    if (Array.isArray(V)) %7B%0A        return '%5B' + V.map(function (v) %7B%0A            return stringify(V);%0A        %7D).join(',') + '%5D';%0A    %7D%0A%0A    if (V === Object(V)) %7B%0A        return '%7B' + Object.keys(V).map(function (k) %7B%0A            return stringify(k) + ':' + stringify(V%5Bk%5D);%0A        %7D).join(',') + '%7D';%0A    %7D%0A%0A    return '%22' + V.replace(/%22/g, '%5C%5C%5C%22') + '%22';%0A%7D;%0A%0A
 /**%0A * F
@@ -2040,13 +2040,8 @@
 urn 
-JSON.
 stri
@@ -2063,431 +2063,8 @@
 text
-, function (K, V) %7B%0A            if (V === undefined) %7B%0A               console.warn('%5BFluxex%5D undefined detected on key %60' + K + '%60! Please fix your store implementation to prevent store undefined into it, or you will see React client side error: %60Invariant Violation: You%5C're trying to render a component to the document using server rendering but the checksum was invalid.%60');%0A            %7D%0A            return V;%0A        %7D
 );%0A 

use homemade stringify