Skip to content

Commit

Permalink
Merge pull request #6 from pubnub/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ManuelFernando authored Nov 1, 2017
2 parents faa5a5b + 843befb commit c6a9d44
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 13 deletions.
7 changes: 6 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: pubnub-react
version: 1.0.2
version: 1.1.0
schema: 1
scm: github.com/pubnub/pubnub-react
files:
- dist/pubnub-react.js
- dist/pubnub-react.min.js
changelog:
- version: v1.1.0
changes:
- type: feature
text: keep the stack of messages with only the latest 100
date: 2017-10-01
- version: v1.0.2
changes:
- type: feature
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[Full Changelog](https://github.com/pubnub/pubnub-react/compare/v1.0.2...v1.1.0)




- 🌟keep the stack of messages with only the latest 100




[Full Changelog](https://github.com/pubnub/pubnub-react/compare/v1.0.1...v1.0.2)


Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,42 @@ componentWillMount() {
...
```

When you are using `getMessage` this is going to keep the latest 100 messages received by default. But you can change this
value when you attach the channel for first time with `getMesage`.

```
...
// the stack for the channel1 will always have the latest 20 messages.
componentWillMount() {
this.pubnub.init(this);
this.pubnub.getMessage('channel1', (msg) => {
console.log(msg);
}, 20);
...
}
...
```
or

```
...
// the stack for the channel1 will always have the latest 20 messages.
componentWillMount() {
this.pubnub.init(this);
this.pubnub.getMessage('channel1', 20);
...
}
...
```

### getPresence

**Rendering presence object from react**
Expand Down
26 changes: 24 additions & 2 deletions dist/pubnub-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ return /******/ (function(modules) { // webpackBootstrap
this._component = component;
this._broadcast = new _broadcast.Broadcast();
this._listener = {};
this._keepMessages = {};

this.addListener(this._listener);
this._autoload.initialize(this);
Expand Down Expand Up @@ -996,21 +997,42 @@ return /******/ (function(modules) { // webpackBootstrap
}

function emit(instance, channel, message) {
var messages = instance._component.state.pn_messages[channel];
var keepMessages = instance._keepMessages[channel];

messages.push(message);

if (keepMessages && messages.length > keepMessages) {
messages = messages.slice(messages.length - keepMessages);
}

instance._component.setState(function (prevState) {
return {
pn_messages: (0, _immutabilityHelper2.default)(prevState.pn_messages, _defineProperty({}, channel, { $push: [message] }))
pn_messages: (0, _immutabilityHelper2.default)(prevState.pn_messages, _defineProperty({}, channel, { $set: messages }))
};
});

instance._broadcast.emit('message', channel, message);
}

function getMessage(channel, callback) {
function getMessage(channel) {
var _this = this;

var component = this._component;
var callback = void 0;
var keepMessages = 100;

if (arguments.length === 2 && typeof arguments[1] === 'function') {
callback = arguments[1];
} else if (arguments.length === 2 && typeof arguments[1] === 'number') {
keepMessages = arguments[1];
} else if (arguments.length === 3) {
callback = arguments[1];
keepMessages = arguments[2];
}

if (init(component, channel)) {
this._keepMessages[channel] = keepMessages;
this._autoload.getHistory(channel, callback);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/pubnub-react.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stats.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"errors":[],"warnings":[],"version":"1.15.0","hash":"de2757e0bca00089f972","publicPath":"","assetsByChunkName":{"main":"pubnub-react.js"},"assets":[{"name":"pubnub-react.js","size":116513,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":112754,"names":["main"],"files":["pubnub-react.js"],"hash":"6ec28fe444d77d81729e","parents":[],"modules":[],"filteredModules":15,"origins":[{"moduleId":0,"module":"/Users/ManuelFernando/GitHub/pubNub/react/node_modules/babel-loader/lib/index.js!/Users/ManuelFernando/GitHub/pubNub/react/src/pubnub-react.js","moduleIdentifier":"/Users/ManuelFernando/GitHub/pubNub/react/node_modules/babel-loader/lib/index.js!/Users/ManuelFernando/GitHub/pubNub/react/src/pubnub-react.js","moduleName":"./src/pubnub-react.js","loc":"","name":"main","reasons":[]}]}],"modules":[],"filteredModules":15,"children":[]}
{"errors":[],"warnings":[],"version":"1.15.0","hash":"98d6ec9bd7cccb6dfb48","publicPath":"","assetsByChunkName":{"main":"pubnub-react.js"},"assets":[{"name":"pubnub-react.js","size":117233,"chunks":[0],"chunkNames":["main"],"emitted":true},{"name":"stats.json","size":0,"chunks":[],"chunkNames":[]}],"chunks":[{"id":0,"rendered":true,"initial":true,"entry":true,"extraAsync":false,"size":113456,"names":["main"],"files":["pubnub-react.js"],"hash":"23e10d89938f9d652a8c","parents":[],"modules":[],"filteredModules":15,"origins":[{"moduleId":0,"module":"/Users/ManuelFernando/GitHub/pubNub/react/node_modules/babel-loader/lib/index.js!/Users/ManuelFernando/GitHub/pubNub/react/src/pubnub-react.js","moduleIdentifier":"/Users/ManuelFernando/GitHub/pubNub/react/node_modules/babel-loader/lib/index.js!/Users/ManuelFernando/GitHub/pubNub/react/src/pubnub-react.js","moduleName":"./src/pubnub-react.js","loc":"","name":"main","reasons":[]}]}],"modules":[],"filteredModules":15,"children":[]}
25 changes: 23 additions & 2 deletions lib/modules/getMessage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/modules/getMessage.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/pubnub-react.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6a9d44

Please sign in to comment.