{"action":"created","issue":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/665","labels_url":"https://api.github.com/repos/lhorie/mithril.js/issues/665/labels{/name}","comments_url":"https://api.github.com/repos/lhorie/mithril.js/issues/665/comments","events_url":"https://api.github.com/repos/lhorie/mithril.js/issues/665/events","html_url":"https://github.com/lhorie/mithril.js/pull/665","id":87863302,"number":665,"title":"Making Mithril modular","user":{"login":"Mosho1","id":5153007,"avatar_url":"https://avatars.githubusercontent.com/u/5153007?v=3","gravatar_id":"","url":"https://api.github.com/users/Mosho1","html_url":"https://github.com/Mosho1","followers_url":"https://api.github.com/users/Mosho1/followers","following_url":"https://api.github.com/users/Mosho1/following{/other_user}","gists_url":"https://api.github.com/users/Mosho1/gists{/gist_id}","starred_url":"https://api.github.com/users/Mosho1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mosho1/subscriptions","organizations_url":"https://api.github.com/users/Mosho1/orgs","repos_url":"https://api.github.com/users/Mosho1/repos","events_url":"https://api.github.com/users/Mosho1/events{/privacy}","received_events_url":"https://api.github.com/users/Mosho1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":21,"created_at":"2015-06-12T21:53:43Z","updated_at":"2015-07-04T10:22:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/lhorie/mithril.js/pulls/665","html_url":"https://github.com/lhorie/mithril.js/pull/665","diff_url":"https://github.com/lhorie/mithril.js/pull/665.diff","patch_url":"https://github.com/lhorie/mithril.js/pull/665.patch"},"body":"This implements the proposal in #651.\r\n\r\n### Summary\r\n\r\nThis is a fairly extensive PR, modifying Mithril to use a package ecosystem. CommonJS-style (for node compatibility) packages together with Webpack (smallest footprint) are used. \r\n\r\n### Structure\r\n\r\nThe following folder structure is used:\r\n```\r\n|-- mithril.js\r\n    |-- src\r\n        |-- index.js\r\n        |-- core\r\n        |   |-- fns.js\r\n        |   |-- init.js\r\n        |   |-- types.js\r\n        |-- helpers\r\n        |   |-- Object.assign.js\r\n        |-- modules\r\n            |-- DOM.js\r\n            |-- http.js\r\n            |-- mock.js\r\n            |-- router.js\r\n            |-- utils.js\r\n```\r\n\r\n`core` includes packages that are used across all modules.\r\n`Object.assign` polyfill is used to combine modules in `index.js`, which is the entry point. More entry points can be configured in webpack's configuration and built/tested individually.\r\n\r\n### Benefits\r\n\r\n1. Mithril as a library can now import modules to for usage within the library.\r\n2. Specialized builds of Mithril can be made.\r\n  * A separate file for each built can be made, for example: `mithril.js`, mithril.DOM.js`, `mithril.router.js` etc.\r\n  * Module ecosystems can use `var m = require('mithril/DOM')` once a build for npm is set up.\r\n3. Modules allow for a more organized codebase which is easy to reason about, refactor, and add to.\r\n\r\n### Changes List\r\n\r\nIn addition to the restructuring, the following changes to the code base were made:\r\n\r\n1. several functions have been extracted to their own modules, and as such, calling them requires namespacing (`fns.propify()` etc.).\r\n\r\n2. I've added this line to `redraw`:\r\n\r\n        var raf = $.requestAnimationFrame, caf = $.cancelAnimationFrame;\r\n\r\n  `$` is where `initialize` is defined, and when we require it `$document` becomes `$.document`. The above functions can't be called like that it would seem, requiring the assignment. Not sure if this is the best solution.\r\n\r\n3. Tests for `console.log` and `document.write` presence have been removed since we don't have a global IIFE anymore. Another method can be used. \r\n\r\n4. `Gruntfile.js` was changed to accommodate webpack.\r\n\r\n5. for testing, `m.deps` is now in `mock.js`. `index.js` has this line:\r\n\r\n        if (typeof global != \"undefined\") global.m = m;\r\n\r\n  and in `tests/mithril-tests.js`:\r\n\r\n        var m = global.m;\r\n\r\n  Since the tests and the script's output object are no longer in the same scope.\r\n\r\n### The cost \r\n\r\nIs a few more milliseconds of loading and evaluating the script, as well as ~2kb of minified script size."},"comment":{"url":"https://api.github.com/repos/lhorie/mithril.js/issues/comments/118498681","html_url":"https://github.com/lhorie/mithril.js/pull/665#issuecomment-118498681","issue_url":"https://api.github.com/repos/lhorie/mithril.js/issues/665","id":118498681,"user":{"login":"impinball","id":4483844,"avatar_url":"https://avatars.githubusercontent.com/u/4483844?v=3","gravatar_id":"","url":"https://api.github.com/users/impinball","html_url":"https://github.com/impinball","followers_url":"https://api.github.com/users/impinball/followers","following_url":"https://api.github.com/users/impinball/following{/other_user}","gists_url":"https://api.github.com/users/impinball/gists{/gist_id}","starred_url":"https://api.github.com/users/impinball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/impinball/subscriptions","organizations_url":"https://api.github.com/users/impinball/orgs","repos_url":"https://api.github.com/users/impinball/repos","events_url":"https://api.github.com/users/impinball/events{/privacy}","received_events_url":"https://api.github.com/users/impinball/received_events","type":"User","site_admin":false},"created_at":"2015-07-04T10:22:51Z","updated_at":"2015-07-04T10:22:51Z","body":"I'm currently getting ready to see how well I can do with this (I'm going to try Webpack first)."}}