This repository was archived by the owner on May 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Добавил возможность посылать тип сообщений-команда #4
Open
UDenis
wants to merge
12
commits into
InnovaCo:master
Choose a base branch
from
UDenis:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
77822b4
add request-responce
4534fe4
fix bugs
12f86ce
updates wrappers
c7a8c6a
refactoring
71babc4
refactoring
05b7716
include Q.js to build file
a1086f9
add jshint
bbceca9
refactoring
bbbd7b9
add test request/on in channel
6585672
Q.js -> pledges
0513133
fix bug
d61ffb7
удалил конфигурирование промисов
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "indent": 4, | ||
| "boss": true, | ||
| "undef": true, | ||
| "curly": true, | ||
| "forin": true, | ||
| "unused": true, | ||
| "newcap": true, | ||
| "eqnull": true, | ||
| "jquery": true, | ||
| "browser": true, | ||
| "noempty": true, | ||
| "latedef": true, | ||
| "camelcase": true, | ||
| "quotmark": "single", | ||
| "scripturl": true, | ||
| "-W030": false, | ||
| "-W015": false, | ||
| "globals": { | ||
| "module": true, | ||
| "define": true, | ||
| "require": true, | ||
| "console": true, | ||
| "exports": true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /** | ||
| * Механизим, добавляющий механизм request-response сообщений. | ||
| * | ||
| * Используется следующая конвенция: если событие вызывается | ||
| * с префиксом `/`, то тип событие - команда и ожидается ответ | ||
| */ | ||
| if (typeof module === 'object' && typeof define !== 'function') { | ||
| var define = function(factory) { | ||
| module.exports = factory(require, exports, module); | ||
| }; | ||
| } | ||
|
|
||
| /*jshint unused:false*/ | ||
| define(function(require, exports, module) { | ||
| var channelTest = /^@/, | ||
| commandTest = /^\//, | ||
| deferred = require('pledges').deferred; | ||
|
|
||
| return function(postal) { | ||
|
|
||
| function request(channel, command) { | ||
| var | ||
| defer = deferred(), | ||
| promise = defer, | ||
| data = { | ||
| __args: null | ||
| }; | ||
|
|
||
| if (typeof channel !== 'string') { | ||
| return promise; | ||
| } | ||
|
|
||
| if (channelTest.test(channel)) { | ||
| channel = channel.substr(1); | ||
| data.__args = Array.prototype.slice.call(arguments, 2); | ||
| } else { | ||
| data.__args = Array.prototype.slice.call(arguments, 1); | ||
| command = channel; | ||
| channel = null; | ||
| } | ||
|
|
||
| if (!channel && this instanceof postal.ChannelDefinition) { | ||
| channel = this.channel; | ||
| } | ||
|
|
||
| function resolve(data) { | ||
| defer.resolve(data); | ||
| } | ||
|
|
||
| function reject(reason) { | ||
| defer.reject(reason); | ||
| } | ||
|
|
||
| function reply(err, data) { | ||
| if (err) { | ||
| reject(err); | ||
| } else { | ||
| resolve(data); | ||
| } | ||
| } | ||
|
|
||
| reply.resolve = resolve; | ||
| reply.reject = reject; | ||
|
|
||
| postal.publish({ | ||
| channel: channel, | ||
| topic: command, | ||
| data: data, | ||
| reply: reply, | ||
| headers: { | ||
| replyable: true | ||
| } | ||
| }); | ||
|
|
||
| return promise; | ||
| } | ||
|
|
||
| postal.request = request; | ||
|
|
||
| postal.ChannelDefinition.prototype.request = request; | ||
|
|
||
| var SubscriptionDefinitionProto = postal.SubscriptionDefinition.prototype, | ||
| originSubscribe = SubscriptionDefinitionProto.subscribe; | ||
|
|
||
| SubscriptionDefinitionProto.subscribe = function(originCallback) { | ||
|
|
||
| function callbackProxy(data, envelope) { | ||
| if (envelope.headers && envelope.headers.replyable) { | ||
| try { | ||
| // если метод вызван через метод ON фасада backbode | ||
| if (originCallback.__original && data.__args) { | ||
| data.__args.unshift(envelope.reply); | ||
| } | ||
|
|
||
| return originCallback.call(this, data, envelope); | ||
| } catch (ex) { | ||
| //console.log(ex); | ||
| envelope.reply(ex); | ||
| } | ||
| } | ||
| return originCallback.apply(this, arguments); | ||
|
|
||
| } | ||
|
|
||
| //в случае если подписались через метод ON | ||
| // сохраняем __original для отписки | ||
| if (originCallback.__original) { | ||
| callbackProxy.__original = originCallback.__original; | ||
| } | ||
|
|
||
| return originSubscribe.call(this, callbackProxy); | ||
| }; | ||
|
|
||
| return postal; | ||
| }; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Оч удобно в комитах добавлять текст
fix #5что автоматически закроет issue #5 при мердже в мастер