CodeMirror binder creator for Matreshka.js
JavaScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.babelrc
.eslintrc.json
.gitignore
.npmignore
.travis.yml
LICENSE Initial commit Oct 20, 2016
README.md fix: Update README Aug 11, 2018
package-lock.json
package.json chore: Add tests to publish scripts Aug 11, 2018
src.js
webpack.config.js

README.md

codemirror-binder npm version Build Status Coverage Status

CodeMirror binder creator for Matreshka.js and defi.js

The binder creator returns a binder which initializes and binds CodeMirror instance (created using fromTextArea function) to a property.

Usage

npm install --save codemirror-binder
import { bindNode } from 'matreshka'; // or import { bindNode } from 'defi';
import codeMirrorBinder from 'codemirror-binder';

// ...
const obj = {};
bindNode(obj, 'code', textarea, codeMirrorBinder());

this.bindNode('code', textarea, codeMirrorBinder()); // for Matreshka class instances

Usage in a browser environment

For non-CJS environment the bundle can be downloaded at gh-pages branch.

In the browser environment the scripts exports a global variable codeMirrorBinder.

<script src="path/to/codemirror-binder.min.js"></script>
defi.bindNode(obj, 'code', textarea, codeMirrorBinder()); // for defi

Matreshka.bindNode(obj, 'code', textarea, codeMirrorBinder()); // for Matreshka + custom objects

this.bindNode('code', textarea, codeMirrorBinder()); // for Matreshka class instances

Configuration

The function accepts one argument: configuration object which is passed into internal call of CodeMirror.fromTextArea. Read the CodeMirror documentation for more info.

bindNode(obj, 'code', textarea, codeMirror({
    lineNumbers: true,
    mode: 'htmlmixed'
}));