@@ -7,11 +7,17 @@ import {
77 formSubscriptionItems ,
88 version as ffVersion
99} from 'final-form'
10- import type { Api , Config , FormSubscription , FormState } from 'final-form'
10+ import type {
11+ Api ,
12+ Config ,
13+ FormSubscription ,
14+ FormState ,
15+ Unsubscribe
16+ } from 'final-form'
1117import type { FormProps as Props , ReactContext } from './types'
1218import shallowEqual from './shallowEqual'
1319import renderComponent from './renderComponent'
14- export const version = '1.0 .0'
20+ export const version = '1.2 .0'
1521
1622export const all : FormSubscription = formSubscriptionItems . reduce (
1723 ( result , key ) => {
@@ -30,7 +36,7 @@ export default class ReactFinalForm extends React.PureComponent<Props, State> {
3036 props : Props
3137 state : State
3238 form : Api
33- unsubscribe : ( ) = > void
39+ unsubscriptions : Unsubscribe [ ]
3440
3541 static childContextTypes = {
3642 reactFinalForm : PropTypes . object
@@ -44,6 +50,7 @@ export default class ReactFinalForm extends React.PureComponent<Props, State> {
4450 children ,
4551 component ,
4652 debug ,
53+ decorators ,
4754 initialValues ,
4855 mutators ,
4956 onSubmit ,
@@ -70,16 +77,24 @@ export default class ReactFinalForm extends React.PureComponent<Props, State> {
7077 warning ( false , e . message )
7178 }
7279 let initialState
73- this . unsubscribe =
74- this . form &&
75- this . form . subscribe ( ( state : FormState ) => {
76- if ( initialState ) {
77- this . notify ( state )
78- } else {
79- initialState = state
80- }
81- } , subscription || all )
80+ this . unsubscriptions = [ ]
81+ if ( this . form ) {
82+ this . unsubscriptions . push (
83+ this . form . subscribe ( ( state : FormState ) => {
84+ if ( initialState ) {
85+ this . notify ( state )
86+ } else {
87+ initialState = state
88+ }
89+ } , subscription || all )
90+ )
91+ }
8292 this . state = { state : initialState }
93+ if ( decorators ) {
94+ decorators . forEach ( decorator => {
95+ this . unsubscriptions . push ( decorator ( this . form ) )
96+ } )
97+ }
8398 }
8499
85100 getChildContext ( ) {
@@ -102,7 +117,7 @@ export default class ReactFinalForm extends React.PureComponent<Props, State> {
102117 }
103118
104119 componentWillUnmount ( ) {
105- this . unsubscribe ( )
120+ this . unsubscriptions . forEach ( unsubscribe => unsubscribe ( ) )
106121 }
107122
108123 render ( ) {
0 commit comments