├── test ├── .eslintrc ├── fixtures │ ├── errorCore.js │ └── spyCore.js ├── utils.js ├── getNextCoreId-test.js ├── tests.webpack.js ├── coreInit-test.js ├── operations-test.js └── loadCore-test.js ├── .babelrc ├── src ├── utils │ └── noop.js ├── index.js ├── getNextCoreId.js ├── coreInit.js ├── operations.js └── loadCore.js ├── demo ├── build │ ├── favicon.png │ └── index.html ├── static │ ├── Lato-Bold.woff │ ├── tiny_grid.png │ ├── Lato-Black.woff │ └── Lato-Regular.woff ├── src │ ├── core.js │ ├── core.error.js │ ├── style2.less │ ├── CoreStatus.js │ ├── core.green.js │ ├── index.js │ ├── style.less │ └── DemoUI.js ├── .babelrc ├── webpack.config.babel.js └── package.json ├── .eslintrc ├── .npmignore ├── CHANGELOG.md ├── .travis.yml ├── scripts └── deploy.sh ├── LICENSE ├── karma.conf.js ├── package.json ├── karma-sauce.conf.js └── README.md /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["transform-object-rest-spread"] 4 | } 5 | -------------------------------------------------------------------------------- /src/utils/noop.js: -------------------------------------------------------------------------------- 1 | /* istanbul ignore next */ 2 | function noop() {} 3 | 4 | export default noop 5 | -------------------------------------------------------------------------------- /demo/build/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chromakode/isolated-core/HEAD/demo/build/favicon.png -------------------------------------------------------------------------------- /demo/static/Lato-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chromakode/isolated-core/HEAD/demo/static/Lato-Bold.woff -------------------------------------------------------------------------------- /demo/static/tiny_grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chromakode/isolated-core/HEAD/demo/static/tiny_grid.png -------------------------------------------------------------------------------- /demo/static/Lato-Black.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chromakode/isolated-core/HEAD/demo/static/Lato-Black.woff -------------------------------------------------------------------------------- /demo/static/Lato-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chromakode/isolated-core/HEAD/demo/static/Lato-Regular.woff -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "airbnb", 4 | "rules": { 5 | "semi": [2, "never"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import coreInit from './coreInit' 2 | import loadCore from './loadCore' 3 | 4 | export { 5 | coreInit, 6 | loadCore, 7 | } 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | demo/ 2 | scripts/ 3 | src/ 4 | test/ 5 | coverage/ 6 | .babelrc 7 | .eslintrc 8 | .eslintignore 9 | .travis.yml 10 | karma*.conf.js 11 | -------------------------------------------------------------------------------- /demo/src/core.js: -------------------------------------------------------------------------------- 1 | import { coreInit } from 'isolated-core' 2 | 3 | coreInit({ 4 | scriptURL: 'main.js', 5 | run: core => require('./').init(core), 6 | }) 7 | -------------------------------------------------------------------------------- /demo/src/core.error.js: -------------------------------------------------------------------------------- 1 | import { coreInit } from 'isolated-core' 2 | 3 | coreInit({ 4 | scriptURL: 'error.js', 5 | run: () => { 6 | throw new Error('this core crashes!') 7 | }, 8 | }) 9 | -------------------------------------------------------------------------------- /test/fixtures/errorCore.js: -------------------------------------------------------------------------------- 1 | import { coreInit } from '../../src' 2 | 3 | coreInit({ 4 | scriptURL: '/base/test/fixtures/errorCore.js', 5 | run: () => { 6 | throw new Error('oh noes!') 7 | }, 8 | }) 9 | -------------------------------------------------------------------------------- /demo/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react"], 3 | "plugins": ["transform-object-rest-spread"], 4 | "env": { 5 | "development": { 6 | "presets": ["react-hmre"], 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | export function cacheBust(url) { 2 | const karma = window.top.karma 3 | if (karma && karma.files.hasOwnProperty(url)) { 4 | return url + '?' + karma.files[url] 5 | } 6 | return url + '?' + String(Math.random()).substr(2) 7 | } 8 | -------------------------------------------------------------------------------- /src/getNextCoreId.js: -------------------------------------------------------------------------------- 1 | export default function getNextCoreId(doc) { 2 | let lastCoreId = doc._lastCoreId 3 | if (lastCoreId === undefined) { 4 | lastCoreId = -1 5 | } 6 | const nextCoreId = lastCoreId + 1 7 | doc._lastCoreId = nextCoreId 8 | return nextCoreId 9 | } 10 | -------------------------------------------------------------------------------- /demo/src/style2.less: -------------------------------------------------------------------------------- 1 | body { 2 | // Thanks to http://subtlepatterns.com/tiny-grid/ 3 | background: url('../static/tiny_grid.png'); 4 | margin: 0; 5 | border: .5rem solid mix(hsla(120, 35%, 64%, 1), black, 35%); 6 | } 7 | 8 | @media (max-width: 420px) { 9 | body { 10 | border-width: .25rem; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## 0.1.1 - 2016-01-29 6 | ### Fixed 7 | - Superficial README updates. 8 | 9 | ## 0.1.0 - 2016-01-29 10 | ### Added 11 | - Initial public release. 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "5" 5 | 6 | script: 7 | - npm run lint 8 | - if [ "$SAUCE_ACCESS_KEY" ]; then npm run test:sauce; else npm run test; fi 9 | 10 | after_success: 11 | - npm install coveralls lcov-result-merger 12 | - $(npm bin)/lcov-result-merger './coverage/*/lcov.info' | $(npm bin)/coveralls 13 | - ./scripts/deploy.sh 14 | -------------------------------------------------------------------------------- /test/getNextCoreId-test.js: -------------------------------------------------------------------------------- 1 | import expect from 'expect' 2 | import getNextCoreId from '../src/getNextCoreId' 3 | 4 | describe('getNextCoreId', () => { 5 | it('increments on each call and sets doc._lastCoreID', () => { 6 | const fakeDoc = {} 7 | expect(getNextCoreId(fakeDoc)).toBe(0) 8 | expect(fakeDoc._lastCoreId).toBe(0) 9 | expect(getNextCoreId(fakeDoc)).toBe(1) 10 | expect(fakeDoc._lastCoreId).toBe(1) 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /test/tests.webpack.js: -------------------------------------------------------------------------------- 1 | // Inspired by: 2 | // https://github.com/deepsweet/isparta-loader 3 | // https://github.com/webpack/karma-webpack#alternative-usage 4 | // http://kentor.me/posts/testing-react-and-flux-applications-with-karma-and-webpack/ 5 | 6 | import 'core-js' 7 | 8 | // Require all tests. 9 | const testsContext = require.context('.', true, /-test.js$/) 10 | testsContext.keys().forEach(testsContext) 11 | 12 | // Require all source files so we get full coverage stats. 13 | const srcContext = require.context('../src/', true) 14 | srcContext.keys().forEach(srcContext) 15 | -------------------------------------------------------------------------------- /demo/src/CoreStatus.js: -------------------------------------------------------------------------------- 1 | import React, { PropTypes } from 'react' 2 | 3 | export default function CoreStatus({ loading, ready, coreRef, error, errorDetail }) { 4 | if (error) { 5 | return {error} error: "{String(errorDetail)}" 6 | } else if (loading) { 7 | return loading... 8 | } else if (ready) { 9 | return core #{coreRef.id} ready! 10 | } 11 | return not loaded 12 | } 13 | 14 | CoreStatus.propTypes = { 15 | loading: PropTypes.bool, 16 | ready: PropTypes.bool, 17 | error: PropTypes.string, 18 | } 19 | -------------------------------------------------------------------------------- /src/coreInit.js: -------------------------------------------------------------------------------- 1 | import loadCore from './loadCore' 2 | import { attachCore } from './operations' 3 | 4 | export default function coreInit(opts) { 5 | if (!window._core) { 6 | // We're running in a top level script. 7 | // Load the first core and attach it. 8 | return loadCore(opts, document).then(coreRef => { 9 | attachCore(coreRef.context, document) 10 | return coreRef 11 | }) 12 | } 13 | 14 | const core = { 15 | id: window._core.id, 16 | args: window._core.args, 17 | ready: handlers => window._core.onReady(handlers), 18 | } 19 | 20 | try { 21 | opts.run(core) 22 | } catch (err) { 23 | window._core.onExecutionError(err) 24 | throw err 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /demo/src/core.green.js: -------------------------------------------------------------------------------- 1 | import { coreInit } from 'isolated-core' 2 | 3 | const CSS2 = { __html: require('./style2.less') } 4 | 5 | coreInit({ 6 | scriptURL: 'green.js', 7 | run: core => { 8 | const React = require('react') 9 | const DemoUI = require('./DemoUI').default 10 | 11 | // Monkeypatch in some extra render nodes. 12 | const origRender = DemoUI.prototype.render 13 | DemoUI.prototype.render = function render() { 14 | return ( 15 |