-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9753 from RocketChat/move-nrr-inside
Move NRR package to inside the project and convert from CoffeeScript
- Loading branch information
Showing
5 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,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}} | ||
``` |
This file contains 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,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)); |
This file contains 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,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'); | ||
}); |