{"id":24081763,"url":"https://github.com/jonathanconway/react-mvp","last_synced_at":"2025-04-30T17:01:38.432Z","repository":{"id":57334956,"uuid":"104007251","full_name":"jonathanconway/react-mvp","owner":"jonathanconway","description":"Lightweight Model-View-Presenter framework for React.","archived":false,"fork":false,"pushed_at":"2017-09-19T00:54:16.000Z","size":43,"stargazers_count":13,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T18:04:33.134Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanconway.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":"2017-09-19T00:46:43.000Z","updated_at":"2023-12-05T00:30:17.000Z","dependencies_parsed_at":"2022-09-01T13:51:57.672Z","dependency_job_id":null,"html_url":"https://github.com/jonathanconway/react-mvp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Freact-mvp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Freact-mvp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Freact-mvp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanconway%2Freact-mvp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanconway","download_url":"https://codeload.github.com/jonathanconway/react-mvp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251748929,"owners_count":21637413,"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":"2025-01-09T23:26:13.959Z","updated_at":"2025-04-30T17:01:37.751Z","avatar_url":"https://github.com/jonathanconway.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-mvp\n\nLightweight Model-View-Presenter framework for React.\n\n![Diagram that depicts the Model View Presenter (MVP) GUI design pattern.](https://upload.wikimedia.org/wikipedia/commons/d/dc/Model_View_Presenter_GUI_Design_Pattern.png)\n\nBootstrapped with [create-react-app-minimal](http://conwy.codes/cram).\n\n## Getting started\n\n### Installing\n\n```\nnpm install react-mvp\n```\n\n### Usage\n\nDeclare your view, as a \"dumb\" component, with all input and output taking place through props (values and event handlers).\n\n```js\nimport React from 'react'\n\nclass TodoApp extends Component {\n  render = () =\u003e {\n    const { todoList, newItem, onAddNewItem, onChangeNewItem } = this.props\n\n    return \u003cdiv\u003e\n      \u003cdiv\u003e\n        \u003clabel\u003eEnter new item\u003c/label\u003e\n        \u003cinput type=\"text\" onChange={onChangeNewItem} value={newItem} /\u003e\n        \u003cbutton onClick={onAddNewItem}\u003eAdd\u003c/button\u003e\n      \u003c/div\u003e\n\n      \u003cul\u003e\n        {todoList.map(item =\u003e\n          \u003cli\u003e{item}\u003c/li\u003e\n        )}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  }\n}\n```\n\nThen declare your model, with any needed defaults.\n\n```js\nclass TodoAppModel {\n  todoList = []\n\n  newItem = ''\n}\n```\n\nThen declare your presenter, as a class that inherits from `Presenter` in react-mvp.\n\n```js\nimport { Presenter } from 'react-mvp'\n\nclass TodoAppPresenter extends Presenter {\n  constructor(model, setModel) {\n    super(model, setModel);\n  }\n\n  onChangeNewItem = event =\u003e\n    this.setModel({\n      newItem: event.target.value\n    })\n\n  onAddNewItem = () =\u003e\n    this.setModel({\n      newItem: '',\n      todoList: this.model.todoList.concat([ this.model.newItem ])\n    })\n}\n```\n\nFinally, hook them all up together, using `connect`, and render the result. (This example assumes a web-browser.)\n\n```js\nimport { connect } from 'react-mvp'\n\nconst App = connect(TodoAppModel, TodoAppPresenter, TodoApp)\n\nimport React from 'react'\nimport ReactDOM from 'react-dom'\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById('root'))\n```\n\n## Contributing\n\nYou're welcome to fork and/or contribute pull-requests and issues to the project.\n\n### Cloning and installing\n\n```bash\ngit clone https://github.com/jonathanconway/react-mvp\ncd react-mvp\nnpm install\n```\n\n### Running tests\n\n```bash\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanconway%2Freact-mvp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanconway%2Freact-mvp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanconway%2Freact-mvp/lists"}