forked from alexlafroscia/ember-react-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27f2ab6
commit 1d9450b
Showing
15 changed files
with
2,396 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ testem.js | |
.node_modules.ember-try/ | ||
bower.json.ember-try | ||
package.json.ember-try | ||
/config/addon-docs.js |
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 |
---|---|---|
@@ -1,52 +1 @@ | ||
import Component from '@ember/component'; | ||
import { get } from '@ember/object'; | ||
import { schedule } from '@ember/runloop'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
export default function WithEmberSupport(Klass) { | ||
return class extends Component { | ||
constructor() { | ||
super(); | ||
|
||
for (const key in Klass.prototype) { | ||
this[key] = Klass.prototype[key]; | ||
} | ||
} | ||
|
||
_getPropsForReact() { | ||
return Object.keys(this.attrs).reduce((acc, key) => { | ||
const value = get(this, key); | ||
|
||
acc[key] = value; | ||
|
||
return acc; | ||
}, {}); | ||
} | ||
|
||
_mountElement() { | ||
this._reactElement = ReactDOM.render( | ||
<Klass {...this._getPropsForReact()} />, | ||
this.element | ||
); | ||
} | ||
|
||
didUpdateAttrs() { | ||
schedule('render', () => { | ||
this._mountElement(); | ||
}); | ||
} | ||
|
||
didInsertElement() { | ||
super.didInsertElement(...arguments); | ||
|
||
this._mountElement(); | ||
} | ||
|
||
willDestroyElement() { | ||
ReactDOM.unmountComponentAtNode(this.element); | ||
|
||
super.willDestroyElement(...arguments); | ||
} | ||
}; | ||
} | ||
export { WithEmberSupport as default } from './with-ember-support'; |
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,57 @@ | ||
import Component from '@ember/component'; | ||
import { get } from '@ember/object'; | ||
import { schedule } from '@ember/runloop'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
/** | ||
* @function WithEmberSupport | ||
* @param {React.Component} klass The React class to "transform" | ||
* @return {Ember.Component} the resulting class | ||
*/ | ||
export function WithEmberSupport(Klass) { | ||
return class extends Component { | ||
constructor() { | ||
super(); | ||
|
||
for (const key in Klass.prototype) { | ||
this[key] = Klass.prototype[key]; | ||
} | ||
} | ||
|
||
_getPropsForReact() { | ||
return Object.keys(this.attrs).reduce((acc, key) => { | ||
const value = get(this, key); | ||
|
||
acc[key] = value; | ||
|
||
return acc; | ||
}, {}); | ||
} | ||
|
||
_mountElement() { | ||
this._reactElement = ReactDOM.render( | ||
<Klass {...this._getPropsForReact()} />, | ||
this.element | ||
); | ||
} | ||
|
||
didUpdateAttrs() { | ||
schedule('render', () => { | ||
this._mountElement(); | ||
}); | ||
} | ||
|
||
didInsertElement() { | ||
super.didInsertElement(...arguments); | ||
|
||
this._mountElement(); | ||
} | ||
|
||
willDestroyElement() { | ||
ReactDOM.unmountComponentAtNode(this.element); | ||
|
||
super.willDestroyElement(...arguments); | ||
} | ||
}; | ||
} |
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,9 @@ | ||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
const AddonDocsConfig = require('ember-cli-addon-docs/lib/config'); | ||
|
||
module.exports = class extends AddonDocsConfig { | ||
// See https://ember-learn.github.io/ember-cli-addon-docs/latest/docs/deploying | ||
// for details on configuration you can override here. | ||
}; |
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,29 @@ | ||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
module.exports = function(deployTarget) { | ||
let ENV = { | ||
build: {} | ||
// include other plugin configuration that applies to all deploy targets here | ||
}; | ||
|
||
if (deployTarget === 'development') { | ||
ENV.build.environment = 'development'; | ||
// configure other plugins for development deploy target here | ||
} | ||
|
||
if (deployTarget === 'staging') { | ||
ENV.build.environment = 'production'; | ||
// configure other plugins for staging deploy target here | ||
} | ||
|
||
if (deployTarget === 'production') { | ||
ENV.build.environment = 'production'; | ||
// configure other plugins for production deploy target here | ||
} | ||
|
||
// Note: if you need to build some configuration asynchronously, you can return | ||
// a promise that resolves with the ENV object instead of returning the | ||
// ENV object synchronously. | ||
return ENV; | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// BEGIN-SNIPPET basic-component.js | ||
import React from 'react'; | ||
import WithEmberSupport from 'ember-cli-react'; | ||
|
||
@WithEmberSupport | ||
export default class FromMixin extends React.Component { | ||
export default class BasicComponent extends React.Component { | ||
render() { | ||
return <h1>Hello from React</h1>; | ||
} | ||
} | ||
// END-SNIPPET |
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,8 @@ | ||
{{#docs-demo as |demo|}} | ||
{{#demo.example name='demo-basic-component.hbs'}} | ||
{{basic-component}} | ||
{{/demo.example}} | ||
|
||
{{demo.snippet 'basic-component.js' label='components/basic-component.js'}} | ||
{{demo.snippet 'demo-basic-component.hbs'}} | ||
{{/docs-demo}} |
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,5 @@ | ||
# ember-cli-react | ||
|
||
Why choose one framework or another when you can just have both? | ||
|
||
{{docs/demo/basic-component}} |
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,13 @@ | ||
{{#docs-viewer as |viewer|}} | ||
{{#viewer.nav as |nav|}} | ||
{{nav.item 'Introduction' 'docs.index'}} | ||
{{/viewer.nav}} | ||
|
||
{{#viewer.main}} | ||
<div class="docs-container docs__center"> | ||
<div class="docs-section"> | ||
{{outlet}} | ||
</div> | ||
</div> | ||
{{/viewer.main}} | ||
{{/docs-viewer}} |
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,7 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
beforeModel() { | ||
this.replaceWith('docs'); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,13 +1 @@ | ||
<h2 id="title">Hello from Ember</h2> | ||
|
||
<button {{action (mut showReactComponent) true}}> | ||
Show react component | ||
</button> | ||
|
||
<button {{action (mut showReactComponent) false}}> | ||
Hide react component | ||
</button> | ||
|
||
{{#if showReactComponent}} | ||
{{from-mixin}} | ||
{{/if}} | ||
{{outlet}} |
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
Oops, something went wrong.