{"action":"created","issue":{"url":"https://api.github.com/repos/localForage/localForage/issues/622","repository_url":"https://api.github.com/repos/localForage/localForage","labels_url":"https://api.github.com/repos/localForage/localForage/issues/622/labels{/name}","comments_url":"https://api.github.com/repos/localForage/localForage/issues/622/comments","events_url":"https://api.github.com/repos/localForage/localForage/issues/622/events","html_url":"https://github.com/localForage/localForage/issues/622","id":189005122,"number":622,"title":"pubsub","user":{"login":"wormen","id":8462339,"avatar_url":"https://avatars.githubusercontent.com/u/8462339?v=3","gravatar_id":"","url":"https://api.github.com/users/wormen","html_url":"https://github.com/wormen","followers_url":"https://api.github.com/users/wormen/followers","following_url":"https://api.github.com/users/wormen/following{/other_user}","gists_url":"https://api.github.com/users/wormen/gists{/gist_id}","starred_url":"https://api.github.com/users/wormen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wormen/subscriptions","organizations_url":"https://api.github.com/users/wormen/orgs","repos_url":"https://api.github.com/users/wormen/repos","events_url":"https://api.github.com/users/wormen/events{/privacy}","received_events_url":"https://api.github.com/users/wormen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-13T23:58:08Z","updated_at":"2016-11-14T08:20:32Z","closed_at":"2016-11-14T00:21:20Z","body":"prompt\r\nin your library implemented pubsub?\r\n\r\nif no, whether it is planned to add?\r\nIn the documentation is a description of what is possible to realize this is a links\r\nhttps://developer.mozilla.org/en/docs/Web/Events/storage\r\nhttps://developer.mozilla.org/ru/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\r\n\r\nhttp://tutorials.jenkov.com/html5/local-storage.html"},"comment":{"url":"https://api.github.com/repos/localForage/localForage/issues/comments/260274114","html_url":"https://github.com/localForage/localForage/issues/622#issuecomment-260274114","issue_url":"https://api.github.com/repos/localForage/localForage/issues/622","id":260274114,"user":{"login":"wormen","id":8462339,"avatar_url":"https://avatars.githubusercontent.com/u/8462339?v=3","gravatar_id":"","url":"https://api.github.com/users/wormen","html_url":"https://github.com/wormen","followers_url":"https://api.github.com/users/wormen/followers","following_url":"https://api.github.com/users/wormen/following{/other_user}","gists_url":"https://api.github.com/users/wormen/gists{/gist_id}","starred_url":"https://api.github.com/users/wormen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wormen/subscriptions","organizations_url":"https://api.github.com/users/wormen/orgs","repos_url":"https://api.github.com/users/wormen/repos","events_url":"https://api.github.com/users/wormen/events{/privacy}","received_events_url":"https://api.github.com/users/wormen/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T08:20:32Z","updated_at":"2016-11-14T08:20:32Z","body":"made his own version pubsub, may also nice for you\r\nin web workers also works\r\n\r\n``` js\r\nmodule.exports = class PubSub {\r\n\r\n    constructor(channel) {\r\n        this.isBrowser = (typeof window === `object`);\r\n\r\n        this._store = {};\r\n        this._store[channel] = {time: 0};\r\n\r\n        this.channel = channel;\r\n        this.listener = () => {};\r\n    }\r\n\r\n    get() {\r\n        if(this.isBrowser)\r\n            return JSON.parse(localStorage.getItem(this.channel)).msg;\r\n        else\r\n            return this._store[this.channel].msg;\r\n    }\r\n\r\n    set(data){\r\n\r\n        let obj = {\r\n            msg: data,\r\n            time: Date.now()\r\n        };\r\n\r\n        if(this.isBrowser)\r\n            localStorage.setItem(this.channel, JSON.stringify(obj));\r\n        else\r\n            this._store[this.channel] = obj;\r\n    }\r\n\r\n    publish(data) {\r\n        this.set(data);\r\n        this.listener(this.get());\r\n    }\r\n\r\n    subscribe(listener) {\r\n        this.listener = listener;\r\n\r\n        if(this.isBrowser)\r\n            window.addEventListener('storage', e => {\r\n                if (e.key === this.channel) this.listener(this.get());\r\n            }, false);\r\n    }\r\n};\r\n```\r\n\r\n``` js\r\nlet Channel = new PubSub('my_channel');\r\n\r\n// Easily subscribe, data provided via callback.\r\nChannel.subscribe(data => {\r\n    console.log(data);\r\n});\r\n\r\n// Publish a new message to channel.\r\nChannel.publish({message: 'Hello world!'});\r\n```"}}
{"actor":{"display_login":"wormen"}}