mem-store.js
function create_new() {
        var id

        // Check if we already have an id or if
        // we need to generate a new one.
        if (undefined !== ent.id$) {
          // Take a copy of the existing id and
          // delete it from the ent object. Do
          // save will handle the id for us.
          id = ent.id$
          delete ent.id$

          // Save with the existing id
          return do_save(id, true)
        }

        // Generate a new id
        id = options.generate_id ? options.generate_id(ent) : void 0

        if (undefined !== id) {
          return do_save(id, true)
        } else {
          var gen_id = {
            role: 'basic',
            cmd: 'generate_id',
            name: name,
            base: base,
            zone: zone
          }

          // When we get a respones we will use the id param
          // as our entity id, if this fails we just fail and
          // call reply() as we have no way to save without an id
          seneca.act(gen_id, function(err, id) {
            if (err) return reply(err)
            do_save(id, true)
          })
        }
      }
function create_new() {
        var id

        // Check if we already have an id or if
        // we need to generate a new one.
        if (undefined !== ent.id$) {
          // Take a copy of the existing id and
          // delete it from the ent object. Do
          // save will handle the id for us.
          id = ent.id$
          delete ent.id$

          // Save with the existing id
          return do_save(id, true)
        }

        // Generate a new id
        id = options.generate_id ? options.generate_id(ent) : void 0

        if (undefined !== id) {
          return do_save(id, true)
        } else {
          var gen_id = {
            role: 'basic',
            cmd: 'generate_id',
            name: name,
            base: base,
            zone: zone
          }

          // When we get a respones we will use the id param
          // as our entity id, if this fails we just fail and
          // call reply() as we have no way to save without an id
          seneca.act(gen_id, function(err, id) {
            if (err) return reply(err)
            do_save(id, true)
          })
        }
      }
function create_new ( ) { var id // Check if we already have an id or if // we need to generate a new one. if ( undefined !== ent . id$ ) { // Take a copy of the existing id and // delete it from the ent object. Do // save will handle the id for us. id = ent . id$ delete ent . id$ // Save with the existing id return do_save ( id , true ) } // Generate a new id id = options . generate_id ? options . generate_id ( ent ) : void 0 if ( undefined !== id ) { return do_save ( id , true ) } else { var gen_id = { role : 'basic' , cmd : 'generate_id' , name : name , base : base , zone : zone } // When we get a respones we will use the id param // as our entity id, if this fails we just fail and // call reply() as we have no way to save without an id seneca . act ( gen_id , function ( err , id ) { if ( err ) return reply ( err ) do_save ( id , true ) } ) } }
We will still use do_save to save the entity but we need a place to handle new entites and id concerns.
We will still use do_save to save the entity but we need a place to handle new entites and id concerns .