{"id":17049079,"url":"https://github.com/toddself/rearview","last_synced_at":"2025-03-23T04:24:25.296Z","repository":{"id":14212161,"uuid":"16918910","full_name":"toddself/rearview","owner":"toddself","description":null,"archived":false,"fork":false,"pushed_at":"2014-03-11T01:21:56.000Z","size":188,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T05:12:04.428Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"A Backbone View extension that allows for server side rendering via JSDom","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toddself.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-17T16:28:07.000Z","updated_at":"2014-03-11T01:21:56.000Z","dependencies_parsed_at":"2022-09-15T17:50:12.820Z","dependency_job_id":null,"html_url":"https://github.com/toddself/rearview","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frearview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frearview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frearview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frearview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toddself","download_url":"https://codeload.github.com/toddself/rearview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245054034,"owners_count":20553436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T09:53:49.204Z","updated_at":"2025-03-23T04:24:25.209Z","avatar_url":"https://github.com/toddself.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build status](https://secure.travis-ci.org/toddself/rearview.png)](http://travis-ci.org/toddself/rearview)\n# Rearview\n\nA [Backbone](http://backbonejs.com) view implementation that allows for server-side and client-side rendering. Allows for use with Backbone models/collections or POJOs either attached to the view or passed in at `render` time.\n\n## Installation\n\n`npm install rearview`\n\n## Usage\n\n```javascript\n\u003e var Rearview = require('rearview');\n\u003e var View = Rearview.extend({\n  tmplFn: function(){\n    return 'hi';\n  }\n});\n\u003e var v = new View();\n\u003e v.render()\n'\u003cdiv\u003ehi\u003c/div\u003e'\n```\n\n## Options\nWhen you call `Rearview#extend`, here are some options you can set in addition to the normal ones Backbone provides. If you provide a function which already exists on Rearview, the functions will be composed into a wrapper function, allowing both functions to exist courtesy of [deepestMerge](/toddself/deepest-merge).\n\n### `tmplFn` \u003cspan style=\"background-color: red\"\u003e`[required]`\u003c/span\u003e\nA function which returns your template function. The returned template function will be passed one argument, the current data context, and must return a string of HTML.\n\n### `#setTemplate()`\n```\n/**\n * Sets up the template for a given template\n * @method setTemplate\n * @memberOf BaseView\n * @param  {function} template_data A template function which accepts a context and returns a string which represents the compiled template merged with the context\n * @return {object}           undefined\n */\n```\n\n### `#attachChildren()`\n```\n/**\n * Creates child view(s) and generates the HTML. If this view has not yet\n * rendered, it caches them along with the selector to which they should\n * be attached. If the view is rendered, it attaches them after render\n * @method attachChild\n * @memberOf BaseView\n * @param  {object} View        The view to instantiate\n * @param  {object} Model       A model of data for the view\n * @param  {string} [$selector] The selector to which the view should be attached\n * @param  {object} [options]   A key-pair list of options to additionally pass-in\n * @return {object}          undefined\n */\n```\n\n### `#setParentView`\n```\n/**\n * Sets a reference to the parent view on the child so the child can listen\n * to the parent appropriately\n * @memberOf BaseView\n * @method setParentView\n * @param {object} parent The parent view\n */\n```\n\n### `#render`\n```\n/**\n * Default render instance; gets template, serializes data and attaches\n * the rendered element to the cached `this.$el` reference.\n * @memberOf BaseView\n * @method render\n * @param  {object} data   object to be passed into serializeData\n * @param  {boolean} merge Extend or override local model data. Merging provided by [deepestMerge](/toddself/deepst-merge)\n * @return {string}        Returns the HTML string generated by the render\n */\n```\n\n## Events\n\n* `pre-render` `[both]`: fired before the context is passed into the template function and the HTML returned.\n* `pre-server-render` `[server]`: fired only on the server before `pre-render`.\n* `pre-client-render` `[client]`: fired only on the client before `pre-render`.\n* `post-render` `[both]`: fired after the HTML is generated and attached to the current cached `this.$el`. **caveat**: Does not actually place the HTML into the DOM unless `el` is specified (and exists in `window.document` before view instantiation.)\n* `post-server-render` `[server]`: fired only on the server before `post-render` but after the HTML is generated and attached.\n* `post-client-render` `[client]`: fired only on the client before `post-render` but after the HTML is generated and attached.\n* `data-dirtied` `[both]`: fired when the model or collection attached to the view is altered.\n* `data-cleaned` `[both]`: fired when the changed data has been rendered into the cached `this.$el` reference\n* `view-closing` `[both]`: notifies the current view that it should clean itself up and close\n* `child:close` `[both]`: notifies all attached children views that they should clean themselves up and close\n\n## Method Stubs\nThese methods exist but are implemented as no-ops so you can provide custom methods for these\n\n* `preClientRender`: works similar to the event. Allows for something to be done synchronously in the render pipeline.\n* `preServerRender`: works similar to the event. Allows for something to be done synchronously in the render pipeline.\n* `preRender`: works similar to the event. Allows for something to be done synchronously in the render pipeline.\n* `postClientRender`: works similar to the event. Allows for something to be done synchronously in the render pipeline.\n* `postClientRender`: works similar to the event. Allows for something to be done synchronously in the render pipeline.\n* `postRender`: works similar to the event. Allows for something to be done synchronously in the render pipeline.\n* `dereferenceChild`: Run on a parent view when a child view closes itself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddself%2Frearview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoddself%2Frearview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddself%2Frearview/lists"}