Attempts to commit an entry to your local source chain. It will cause callback to your validateCommit
function. Returns either an error or the hash of the committed entry upon success. The type of the entryData
parameter depends on the entry format of entry. If it's a string entry format then the type must be string. If it's a JSON entry format, then it can by any type, and the value will get appropriately converted to JSON. If it is a links format entry, then the type must by a JSON object.
A links
entry object looks like this
{ Links: [ { Base: "2bDja...", Link: "Fb4aXa...", Tag: "links to" } ] }
Base
and Link
must both be type hash. Tag
can be any string, describing the relationship between Base
and Link
. Tag
will later be used in getLinks. It may optionally contain a 4th property LinkAction
which should be set to HC.LinkAction.Del
in order to mark the link as deleted. See the examples below.
entryType: string
entryData: any-type
Returns: hash-string OR error
/* This is an example of a function you might have in your code for committing a "post" entry in a blog or social-media-sharing type of app. It illustrates two aspects of committing data to your local chain. The first is committing a regular "data" style entry, and the second is committing Holochain's links type entry. When you commit a post, you would probably also want to commit links on your identity hash for people to be able to look up a list of your posts. Make sure that you complete the proper validation functions too. For the first commit, you will need to check your validateCommit and validatePut functions, for the second commit, you'll need to check validateCommit, validatePut, and validateLink. */ function createPost(post) { // Commit post entry to my source chain var hash = commit("post",post); // On the DHT, put a link from my hash to the hash of the new post var me = App.Agent.Hash; commit("post_links",{ Links: [ {Base: me,Link: hash, Tag: "post"} ] }); // Returns the hash of the new post to the caller return hash; } // Note that if you want to "remove" a links type entry, you also use commit. That looks something like this: function removePost(postHash) { // Use remove to remove the post entry remove(postHash); // On the DHT, mark the links as deleted var me = App.Agent.Hash; commit("post_links",{ Links: [ { Base: me, Link: postHash, Tag: "post", LinkAction: HC.LinkAction.Del } ] }); // return success return true; }