-
Notifications
You must be signed in to change notification settings - Fork 44
Add code examples to repository #32
Comments
I fully agree, @RichardLitt . We never give enough examples, in a tutorial. I made a sample JavaScript of I copy it below because I don't know where the maintainers of the Tutorial want to structure the repository itself. Personally I'd add it as a bonus at the end of So here is the JavaScript code, for whatever if can help: /*
* Main JavaScript program to exercise the functions of the Tutorial '01_Basics.md'
* June 2021
* [email protected] and [email protected]
*/
// Require the dependencies
const Ipfs = require ('ipfs');
const OrbitDB = require ('orbit-db');
// make a global variable of the IPFS node interface
var node;
// main function: create IPFS node and OrbitDB node + database
async function create() {
console.log(' -> calling create IPFS node;')
// create an IPFS node
node = await Ipfs.create({
preload: {enabled: false},
repo: './ipfs',
EXPERIMENTAL: {pubsub: true},
config: {
Bootstrap: [],
Addresses: {Swarm: []}
}
})
console.log(' -> calling init database;')
// follow with orbitDB database demo
_init()
}
async function _init() {
// create an OrbitDB interface instance on the IPFS node
const orbitdb = await OrbitDB.createInstance(node)
console.log(" --> IPFS node's id: ", orbitdb.identity.id)
const defaultOptions = { accessController: {
write: [orbitdb.identity.id] }
}
const docStoreOptions = {
...defaultOptions,
indexBy: 'hash'
}
// create a specific "docstore' database
const pieces = await orbitdb.docstore('pieces', docStoreOptions)
console.log(" ----> pieces.options.accessControllerAddress = ", pieces.options.accessControllerAddress)
console.log(" ----> pieces.id = ", pieces.id)
console.log(" ----> pieces.identity._id = ", pieces.identity._id)
console.log(" ----> pieces.address root = ", pieces.address.root, ', path =', pieces.address.path)
// ... more to come
}
create(); Executing it will give % node index.js
-> calling create IPFS node;
-> calling init database;
--> IPFS node's id: 03ecc23e7dfa8d1837ba979e719e934879c80dbd62fa0f42c84093f3ae53090e86
----> pieces.options.accessControllerAddress = /ipfs/zdpuAxrg7DS7h7bdeuBuV5JFxjgc4bhVEajGxJUsLH2kjvCqv
----> pieces.id = /orbitdb/zdpuAxtiGj9xZaXCJx1z5852ZUYWJ8TjHeKBpMruUs7nNS8CC/pieces
----> pieces.identity._id = 03ecc23e7dfa8d1837ba979e719e934879c80dbd62fa0f42c84093f3ae53090e86
----> pieces.address root = zdpuAxtiGj9xZaXCJx1z5852ZUYWJ8TjHeKBpMruUs7nNS8CC , path = pieces end execution by typing Control-C |
Allow a humble feedback from a self-learning beginner. There are 2 kinds of tutorials: (1) interactive courses and (2) offline self-paced courses
In addition, all self-learners follow the course for a specific programming purpose, so at the end they have to convert the REPL into a JavaScript program. Curently it's an exercise left to the reader. It would improve tremensously the value of the course if such JavaScript programs were provided. This is what I did for my own needs with the code above. It would help if each tutorial ends with a sample code that reproduces the REPL made during the tutorial. Note: ProtoSchool is between the 2. It is self-paced, without REPL but its coding exercises have immediate feed back and solutions, like an interactive REPL-based course. It's marvelous and as good as it can be, replicating the feeling of REPL using code snippets. But the feedback messages don't give much clue on what went wrong when there is a mistake. With a piece of code, the learner can add liberally console.log to find what went wrong. My 2 cents... |
Thank you for the thoughtful feedback! |
Questions:
You may reply "just try" 😂 but I wanted to make sure of the answer from an IPFS/OrbitDB insider |
|
Both worked. Thanks. So we can answer positively to both. But of course we haven't really tried exercising
|
Let's also add them on IPFS, and point to the repo and IPFS versions directly.
The text was updated successfully, but these errors were encountered: