-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I think example should be as simple as possible. #9
Comments
Hey @askucher, thanks for using Telepat! |
Hi. @gabidobo . I don't use the telepat. But I see we have same thinking about usage of json-merge and socket.io I want to share my clues with you and if you like it then cooperate with you in order to implement it I think the api should look like //client
telepat = Telepat("unique-id")
telepat.plug("backend", { secretKey: "XXX", url: "https://..." })
telepat.prop = 123 here the Telepat should send the socket message to the server with delta of JSON in order to synchronize the data //server
telepat = Telepat("unique-id")
telepat.plug("frontend", { secretKey: "XXX" })
telepat.then(function(delta) {
console.log(telepat.prop) //=> 123
telepat.prop = "321"
}); here the Telepat should send the socket message to the client with delta of JSON in order to synchronize the data //client
telepat = Telepat("unique-id")
telepat.then(function(delta) {
console.log(telepat.prop) //=> 321
}); Then we can bind the telepat with database in order to save data from user input. //server
telepat.plug("mongodb", { connectionString: "XXX" }) It is very useful for rapid prototyping of application and show to investors Then we can bind the telepat with localStorage in order to keep application working even when connection is interrupted //client
telepat.plug("localStorage") Then we can bind the telepat with deltaLog.log file in order to data the data flow //client
telepat.plug("deltaLog", { file: "./deltaLog.log" }) Then we can bind the sharedObject with workflow in order to fire serverside actions like sendmail or another curstomActivity //client
telepat.plug("workflow", { fromFile: "./workflow.js" }) And It would be good to think about transaction to handle errors function success() {
}
function error(delta) {
//your delta has not been processed correctly. Your data is restored
//Please process your delta again
this.wait(1000).tryProcess(delta);
}
telepat.then(success, error) And finally how to write the plugin: //server
module.exports = function(Telepat) {
Telepat.plugin("frontend", function(options, delta) {
//..
})
Telepat.plugin("mongodb", function(options, delta) {
//..
})
Telepat.plugin("deltaLog", function(options, delta) {
//..
})
Telepat.plugin("workflow", function(options, delta) {
//..
})
}
//when user does the require("telepat") it can parse "node_modules/telepat-plugin-*" and find all plugins //client
//Telepat is global object
Telepat.plugin("backend", function(options, delta) {
//..
})
Telepat.plugin("localStorage", function(options, delta) {
//..
})
How to install #install backend
npm i --save telepat
npm i --save telepat-plugin-frontend
npm i --save telepat-plugin-mongodb
#install frontend (should not use browserify for ease)
bower i --save telepat
bower i --save telepat-plugin-backend
bower i --save telepat-plugin-localstorage
#where telepat.js is same for frontend and backend.
So, the complex example should look like //server
Telepat = require("telepat")
chat = Telepat("chat")
chat.plug("mongodb", { connectionString: "user:[email protected]" })
chat.plug("frontend", { port: 3000 });
chat.rooms = [ {title: "General", messages: []}, { title: "Random", messages:[] } ] //client
chat = Telepat("chat")
chat.plug("backend", { port: 3000 })
chat.plug("localStorage");
//use chat to render view
And if you like it I can become a collaborator :) |
Please let me know what you think. If you don't like it I will create my own framework based on this spec https://gist.github.com/askucher/9e1c63b1010eff83d409 |
No description provided.
The text was updated successfully, but these errors were encountered: