Commit graph

1151 commits

Author SHA1 Message Date
Leo Horie
cba577dfd0 Merge pull request #806 from mrtracy/parameterized-components
Typescript: Support for Parameterized Components
2015-10-14 13:28:53 -04:00
Matt Tracy
1cdb66b20d Typescript: Support for Parameterized Components
Previously, the Typescript definition file did not support parameterized
components. The `component()` function did accept additional arguments, but the
`MithrilComponent<T>` interface did not allow components to have any additional
arguments in either their `controller()` or `view()` methods.

Properly supporting flexible variadic parameters in typescript is somewhat
challenging. Tuple types are close, but would only work if the signature of
`controller` and `view` accepted arrays of arguments:
```
interface MithrilStatic {
  component<TController extend controller, TRest extends any[]>(
    component: ParameterizedMithrilComponent<TController, TRest>,
    ...args:TRest
  ) : TController
}

interface ParameterizedMithrilComponent<TController extend controller, TRest
extends any[]> {
  // Doesn't match mithril's component interface; we want to unpack the contents
  // of TRest
  controller: (args: TRest) => TController,
  view: (ctrl: TController, args: TRest)
}
```

Therefore, I have gone with a more traditional method of defining several
overloads of m.component(), each with a different number of extra parameters.
Because of this, the first four parameters to m.component() will be correctly
type checked (i.e. if the Component's controller defines the parameter, it must
be supplied to m.component). Additional parameters beyond the first four are
allowed, but are caught via an `...args:any[]` and thus are not type checked.
2015-09-30 16:44:45 -04:00
Leo Horie
80f43c260b fix file size in docs 2015-09-28 22:26:41 -04:00
Leo Horie
d6e68d0144 Merge pull request #798 from Petroochio/library-size
Update README gzip size statement
2015-09-23 19:02:30 -04:00
Peter Gyory
9b50235dd6 Update README gzip size statement 2015-09-23 16:41:26 -04:00
Leo Horie
8fa84c33f8 Merge pull request #783 from mt-caret/next
Fix sample code in m.request documentation
2015-08-28 09:49:55 -04:00
Leo Horie
626144f34c Merge pull request #775 from deomitrus/patch-1
Grammar/spelling fix
2015-08-28 09:20:28 -04:00
Leo Horie
e41e84eaad Merge pull request #771 from Zalmoxisus/next
Fix SyntaxError in the render example
2015-08-28 09:20:12 -04:00
Leo Horie
1b326ee18f Merge pull request #781 from mkautzmann/next
Change m.module to m.mount in documentation
2015-08-28 09:19:16 -04:00
Masayuki Takeda
f9953b8f74 m.request: fix sample code in documentation 2015-08-28 22:18:46 +09:00
Matheus Kautzmann
343ffc8d36 m.module -> m.mount: fix sample code in HTML files 2015-08-28 09:07:08 -03:00
Matheus Kautzmann
dfa1da0652 m.module -> m.mount: fix README 2015-08-27 17:05:27 -03:00
Deomitrus
322ec7e120 Grammar/spelling fix 2015-08-24 21:08:40 -04:00
Mihail Diordiev
a746d67267 Fix typo in the example of data binding 2015-08-22 19:43:05 +03:00
Mihail Diordiev
57c9cfa76b Fix SyntaxError in the render example 2015-08-20 01:47:27 +03:00
Leo Horie
d3cbbef4d5 Merge pull request #766 from avesus/patch-2
Module -> mount rename: fix a documentation link
2015-08-18 22:07:44 -04:00
Leo Horie
23a7811ad7 Merge pull request #767 from jakobdamjensen/next
Make m.route.param() return all params
2015-08-18 22:07:18 -04:00
Jakob Dam Jensen
caf1138c31 Make m.route.param() return all params #737 2015-08-18 20:44:58 +02:00
Ivan Borisenko
8a8829c2e1 Module -> mount rename: fix a documentation link 2015-08-18 21:42:08 +03:00
Leo Horie
7a5980631e Merge pull request #739 from dgilland/origin/feature-propify-finally
Don't pass value/reason to promise.finally callback.
2015-08-04 15:03:47 -04:00
Leo Horie
5944ed026b Merge remote-tracking branch 'origin/next' into next 2015-08-04 15:02:00 -04:00
Leo Horie
cfdc0a27ce add badge for supported source 2015-08-04 15:01:37 -04:00
Leo Horie
ab8af3ea1d Merge pull request #741 from impinball/next
Bump npm version
2015-08-04 14:52:18 -04:00
Leo Horie
fe65aa748c Merge pull request #746 from gregdking/next
#745 Remove references to DOM nodes when unmounting (Follow-up to #727)
2015-08-04 14:51:55 -04:00
Leo Horie
282da527af Merge pull request #753 from marcolamberto/next
Fixes #721. Firefox insertAdjacentHTML updating text nodes
2015-08-04 14:51:36 -04:00
Leo Horie
7b070fd679 Merge pull request #754 from patrkris/closure-externs
Update externs for Google Closure compiler
2015-08-04 14:51:06 -04:00
Patrick Kristiansen
132fe16176 Update externs for Google Closure compiler 2015-08-04 16:57:13 +02:00
Marco Lamberto
713b458aea Better detection for Range support. 2015-08-04 13:01:07 +02:00
Marco Lamberto
9a42242454 Fixes #721. Firefox insertAdjacentHTML updating text nodes with "beforeend" instead of creating new ones. 2015-08-04 12:16:29 +02:00
Leo Horie
a9ab36388b Merge pull request #749 from pelonpelon/patch-19
allow m.withAttr callback to determine its own `this` [non-breaking]
2015-08-03 09:35:00 -04:00
Leo Horie
c01c07d648 Merge pull request #751 from islahul/next
style fixes spaces and indentation
2015-08-03 09:34:07 -04:00
islahul
49412ea96b style fixes spaces and indentation
Signed-off-by: islahul <islahulzunjani@gmail.com>
2015-08-03 09:54:58 +05:30
pelonpelon
352d093d90 test for correct this on m.withAttr callback 2015-08-01 15:01:38 -05:00
pelonpelon
72c039c4dc allow m.withAttr callback to determine it's own this [non-breaking change]
Background:

In ES6 we now have `Object.setPrototypeOf` which makes prototype delegation an alternative to *sugary*, fake class coding patterns. This can be accomplished in ES5, but ES6 is much more elegant. Here is a basic example. `new` is never used and `this` is very easy to follow.

Working example with changes to mithril.js on lines 854, 858, 859 *only*.
http://jsbin.com/nopugo/1/edit?js,console,output

```javascript

'use strict'

const m = require('mithril')

const DataModel = {
    data: [1,2,3],
    getData(){
        console.log('getting data from server')
        return this.data
    },
    postData(val){
        console.log('sending data to server')
        this.data.push(val)
    }
}
const ViewModel = {
    filterEvenData: function() {
        return this.getData().filter((val) => (val % 2 === 0) && (+val !== 0))
    },
    addNewData: function(val){
        console.log('adding new data', val)
        this.postData(val)
    }
}

var Model = Object.setPrototypeOf(ViewModel, DataModel)

const App = {

    controller(){},

    view(ctrl){
        return m('div', [
            m('pre', [ 'EVEN NUMBERS IN DATA\n',
                this.filterEvenData().map((key,i) =>`${i+1} = ${key}\n`)                
            ]),
            m('div', 'Enter a number'),
            m('input[placeholder=number]', {

                // addNewData is called with **this** === undefined unless we pass `this` to Function.prototype.call in m.withAttr
                onchange: m.withAttr('value', App.addNewData, App),
                value: null
                }
            )
        ]) 
    }
}
Object.setPrototypeOf(App, Model)

m.mount(document.body, App)

```
2015-08-01 14:51:18 -05:00
Greg King
c46567ab81 #745 Remove references to DOM nodes when unmounting
When a null component is passed into m.mount(), remove references to the root DOM element from:
- roots
- cellCache
- nodeCache

And remove the associated entries from:
- controllers
- components
2015-07-29 09:40:32 -04:00
impinball
5111c75746 Bump npm version
Fixes #740. It really needs it... :(

Also, I fixed some weird indentation going on in that area of the package.json
file (mixed spaces/tabs).
2015-07-27 18:48:08 -04:00
Derrick Gilland
937b20984d Update promise.finally test for non-propagation of promise value to finally callback. 2015-07-27 11:29:08 -04:00
Derrick Gilland
1dc8c31632 Don't pass value/reason to promise.finally callback.
This behavior is inline with ES6.
2015-07-27 11:21:17 -04:00
Derrick Gilland
a52c00fb5f Reformat function syntax style to be in-line with overall style. 2015-07-27 10:38:21 -04:00
Leo Horie
a23a32a3d9 Merge pull request #734 from dgilland/feature-propify-finally
Add `finally` to promise-like object.
2015-07-27 09:39:37 -04:00
Derrick Gilland
23930871a1 Add finally to promise-like object.
Closes #680
2015-07-24 16:57:45 -04:00
Leo Horie
08ebb97ea7 bump version 2015-07-23 23:43:38 -04:00
Leo Horie
ed3f3f0686 document component shorthand syntax 2015-07-23 23:43:19 -04:00
Leo Horie
2b24c7a64d changing links to point to absolute path 2015-07-23 23:25:28 -04:00
Leo Horie
bc94836931 Merge branch 'Naddiseo-patch-1' into next 2015-07-23 23:15:27 -04:00
Leo Horie
0d7cc43bfe Merge branch 'patch-1' of https://github.com/Naddiseo/mithril.js into Naddiseo-patch-1
Conflicts:
	tests/mithril-tests.js
2015-07-23 23:15:05 -04:00
Leo Horie
a57b1986ac update change log 2015-07-23 23:13:03 -04:00
Leo Horie
c8ae577c63 #660 return empty object if parsing empty string 2015-07-23 23:11:41 -04:00
Leo Horie
34a96d9428 added links to relevant sections 2015-07-23 23:05:09 -04:00
Leo Horie
2fe869e4f0 fix memory release check 2015-07-23 22:33:15 -04:00