Add example shwing how to customise, make customising work and document all the ways in which browserify will break and how to work around it being dumb.
This commit is contained in:
parent
7a8eae09ff
commit
6c35908949
7 changed files with 161 additions and 11 deletions
40
examples/custom/CustomMTextTile.js
Normal file
40
examples/custom/CustomMTextTile.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
Copyright 2015 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
||||
var MTextTileController = require("matrix-react-sdk/src/controllers/molecules/MTextTile");
|
||||
|
||||
module.exports = React.createClass({
|
||||
displayName: 'MTextTile',
|
||||
mixins: [MTextTileController],
|
||||
|
||||
render: function() {
|
||||
var content = this.props.mxEvent.getContent();
|
||||
return (
|
||||
<span className="mx_MTextTile" onClick={this.onClick}>
|
||||
{content.body}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
|
||||
onClick: function(ev) {
|
||||
global.alert(this.props.mxEvent.getContent().body);
|
||||
}
|
||||
});
|
||||
|
4
examples/custom/README.md
Normal file
4
examples/custom/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
matrix-react-example
|
||||
====================
|
||||
|
||||
An example of how to use the Matrix React SDK to build a more customised app
|
12
examples/custom/index.html
Normal file
12
examples/custom/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!doctype html>
|
||||
<html lang="en" style="height: 100%; overflow: hidden">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Matrix Flux</title>
|
||||
</head>
|
||||
<body style="height: 100%; ">
|
||||
<section id="matrixchat" style="height: 100%; "></section>
|
||||
<script src="bundle.js"></script>
|
||||
<link rel="stylesheet" href="node_modules/matrix-react-sdk/bundle.css">
|
||||
</body>
|
||||
</html>
|
40
examples/custom/index.js
Normal file
40
examples/custom/index.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
Copyright 2015 OpenMarket Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Remember to make your project depend on react directly as soon as
|
||||
// you add a require('react') to any file in your project. Do not rely
|
||||
// on react being pulled in via matrix-react-sdk: browserify breaks
|
||||
// horribly in this situation and can end up pulling in multiple copies
|
||||
// of react.
|
||||
var React = require("react");
|
||||
|
||||
// We pull in the component broker first, separately, as we need to replace
|
||||
// components before the SDK loads.
|
||||
var ComponenetBroker = require("matrix-react-sdk/src/ComponentBroker");
|
||||
|
||||
var CustomMTextTile = require('./CustomMTextTile');
|
||||
|
||||
ComponenetBroker.set('molecules/MTextTile', CustomMTextTile);
|
||||
|
||||
var MatrixReactSdk = require("matrix-react-sdk");
|
||||
//var MatrixReactSdk = require("../../src/index");
|
||||
|
||||
React.render(
|
||||
<MatrixReactSdk.MatrixChat />,
|
||||
document.getElementById('matrixchat')
|
||||
);
|
29
examples/custom/package.json
Normal file
29
examples/custom/package.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "matrix-react-example",
|
||||
"version": "0.0.1",
|
||||
"description": "Example usage of matrix-react-sdk",
|
||||
"author": "matrix.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/matrix-org/matrix-react-sdk"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"browserify": "^10.2.3",
|
||||
"envify": "^3.4.0",
|
||||
"http-server": "^0.8.0",
|
||||
"matrix-react-sdk": "../../",
|
||||
"npm-css": "^0.2.3",
|
||||
"parallelshell": "^1.2.0",
|
||||
"reactify": "^1.1.1",
|
||||
"uglify-js": "^2.4.23",
|
||||
"watchify": "^3.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "browserify -t [ envify --NODE_ENV production ] -g reactify index.js | uglifyjs -c -m -o bundle.js",
|
||||
"start": "parallelshell 'watchify -v -d -g reactify index.js -o bundle.js' 'http-server'"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^0.13.3"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue