-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds createComponentAtom util to use Ember.Component as atoms
- Loading branch information
Showing
6 changed files
with
213 additions
and
12 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,31 @@ | ||
const RENDER_TYPE = 'dom'; | ||
|
||
import { ADD_ATOM_HOOK, REMOVE_ATOM_HOOK } from '../components/mobiledoc-editor/component'; | ||
|
||
function renderFallback() { | ||
let element = document.createElement('span'); | ||
element.innerHTML = '[placeholder for Ember atom]'; | ||
return element; | ||
} | ||
|
||
export default function createComponentAtom(name) { | ||
|
||
return { | ||
name, | ||
type: RENDER_TYPE, | ||
render(atomArg) { | ||
let {env, options} = atomArg; | ||
if (!options[ADD_ATOM_HOOK]) { | ||
return renderFallback(); | ||
} | ||
|
||
let { atom, element } = options[ADD_ATOM_HOOK](atomArg); | ||
let { onTeardown } = env; | ||
|
||
onTeardown(() => options[REMOVE_ATOM_HOOK](atom)); | ||
|
||
return element; | ||
} | ||
}; | ||
|
||
} |
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,33 @@ | ||
import createComponentAtom from 'ember-mobiledoc-editor/utils/create-component-atom'; | ||
import { module, test } from 'qunit'; | ||
import MobiledocDOMRenderer from 'mobiledoc-dom-renderer'; | ||
|
||
module('Unit | Utility | create component atom'); | ||
|
||
test('it creates an atom', function(assert) { | ||
var result = createComponentAtom('foo-atom'); | ||
assert.ok(result.name === 'foo-atom' && | ||
result.type === 'dom' && | ||
typeof result.render === 'function', | ||
'created a named atom' | ||
); | ||
}); | ||
|
||
test('it creates a renderable atom', function(assert) { | ||
var atom = createComponentAtom('foo-atom'); | ||
let renderer = new MobiledocDOMRenderer({atoms: [atom]}); | ||
|
||
let {result} = renderer.render({ | ||
version: '0.3.0', | ||
atoms: [ | ||
['foo-atom', '', {}] | ||
], | ||
sections: [ | ||
[1, 'P', [ | ||
[1, [], 0, 0]] | ||
] | ||
] | ||
}); | ||
|
||
assert.ok(result, 'atom rendered'); | ||
}); |