Skip to content
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

Move NRR package to inside the project and convert from CoffeeScript #9753

Merged
merged 2 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ rocketchat:version
rocketchat:videobridge
rocketchat:webrtc
rocketchat:wordpress
rocketchat:nrr

konecty:change-case
konecty:delayed-task
konecty:mongo-counter
konecty:multiple-instances-status
konecty:nrr
konecty:user-presence

deepwell:bootstrap-datepicker2
Expand Down
2 changes: 1 addition & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ konecty:change-case@2.3.0
konecty:delayed-task@1.0.0
konecty:mongo-counter@0.0.5_3
konecty:multiple-instances-status@1.1.0
konecty:nrr@2.0.2
konecty:user-presence@2.0.1
launch-screen@1.1.1
less@2.7.12
Expand Down Expand Up @@ -191,6 +190,7 @@ rocketchat:message-snippet@0.0.1
rocketchat:message-star@0.0.1
rocketchat:migrations@0.0.1
rocketchat:monitoring@2.30.2_3
rocketchat:nrr@1.0.0
rocketchat:oauth2-server@2.0.0
rocketchat:oauth2-server-config@1.0.0
rocketchat:oembed@0.0.1
Expand Down
18 changes: 18 additions & 0 deletions packages/rocketchat-nrr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# NRR - Non-Reactive Render

This package adds a helper to render templates with less reactivity and computations.
This is ideal to improve the render of a high amount of data.

# Use
```handlebars
{{#nrr nrrargs 'templateName' dataContext}}{{/nrr}}
```
or
```handlebars
{{#nrr nrrargs 'templateName' data1=data1 data2=data2}}{{/nrr}}
```

# Example
```handlebars
{{#nrr nrrargs 'message' message}}{{/nrr}}
```
63 changes: 63 additions & 0 deletions packages/rocketchat-nrr/nrr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint new-cap:0 */

import { Template } from 'meteor/templating';
import { Blaze } from 'meteor/blaze';
import { HTML } from 'meteor/htmljs';
import { Spacebars } from 'meteor/spacebars';
import { Tracker } from 'meteor/tracker';

Blaze.toHTMLWithDataNonReactive = function(content, data) {
const makeCursorReactive = function(obj) {
if (obj instanceof Meteor.Collection.Cursor) {
return obj._depend({
added: true,
removed: true,
changed: true
});
}
};

makeCursorReactive(data);

if (data instanceof Spacebars.kw && Object.keys(data.hash).length > 0) {
Object.keys(data.hash).forEach(key => {
makeCursorReactive(data.hash[key]);
});

data = data.hash;
}

return Tracker.nonreactive(() => Blaze.toHTMLWithData(content, data));
};

Blaze.registerHelper('nrrargs', function() {
return {
_arguments: arguments
};
});

Blaze.renderNonReactive = function(templateName, data) {
const { _arguments } = this.parentView.dataVar.get();

[templateName, data] = _arguments;

return Tracker.nonreactive(() => {
const view = new Blaze.View('nrr', () => {
return HTML.Raw(Blaze.toHTMLWithDataNonReactive(Template[templateName], data));
});

view.onViewReady(() => {
const { onViewReady } = Template[templateName];
return onViewReady && onViewReady.call(view, data);
});

view._onViewRendered(() => {
const { onViewRendered } = Template[templateName];
return onViewRendered && onViewRendered.call(view, data);
});

return view;
});
};

Blaze.registerHelper('nrr', Blaze.Template('nrr', Blaze.renderNonReactive));
12 changes: 12 additions & 0 deletions packages/rocketchat-nrr/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Package.describe({
name: 'rocketchat:nrr',
summary: 'Non-Reactive render',
version: '1.0.0',
git: ''
});

Package.onUse(function(api) {
api.use('ecmascript');

api.mainModule('nrr.js');
});