コード例 #1
0
ファイル: PureComponent.cs プロジェクト: widra/Bridge.React
 private void ComponentDidUpdate(WrappedValue <TProps> previousProps)
 {
     ComponentDidUpdate(ComponentPropsHelpers.UnWrapValueIfDefined(previousProps));
 }
コード例 #2
0
ファイル: PureComponent.cs プロジェクト: widra/Bridge.React
 private bool ShouldComponentUpdate(WrappedValue <TProps> nextPropsIfAny)
 {
     return(!ComponentPropsHelpers.DoPropsReferencesMatch(this.props, ComponentPropsHelpers.UnWrapValueIfDefined(nextPropsIfAny)));
 }
コード例 #3
0
ファイル: PureComponent.cs プロジェクト: widra/Bridge.React
 private void ComponentWillUpdate(WrappedValue <TProps> nextProps)
 {
     ComponentWillUpdate(ComponentPropsHelpers.UnWrapValueIfDefined(nextProps));
 }
コード例 #4
0
ファイル: PureComponent.cs プロジェクト: widra/Bridge.React
 // These are the life cycle methods that React calls - they have to unwrap the props and state references (if provided) in order to pass them on to the methods above
 // (the life cycle methods that derived classes may make use of)
 private void ComponentWillReceiveProps(WrappedValue <TProps> nextPropsIfAny)
 {
     ComponentWillReceiveProps(ComponentPropsHelpers.UnWrapValueIfDefined(nextPropsIfAny));
 }
コード例 #5
0
ファイル: Component.cs プロジェクト: widra/Bridge.React
 private bool ShouldComponentUpdate(WrappedValue <TProps> nextPropsIfAny, WrappedValue <TState> nextStateIfAny)
 {
     return(ShouldComponentUpdate(ComponentPropsHelpers.UnWrapValueIfDefined(nextPropsIfAny), ComponentPropsHelpers.UnWrapValueIfDefined(nextStateIfAny)));
 }
コード例 #6
0
 public static TProps UnWrapValueIfDefined <TProps>(WrappedValue <TProps> wrappedValueIfAny)
 {
     return(Script.Write <TProps>("{0} ? {0}.value : null", wrappedValueIfAny));
 }
コード例 #7
0
        public static WrappedValue <TProps> WrapProps <TProps>(TProps propsIfAny)
        {
            // Try to extract a Key value from the props - it might be a simple "key" value or it might be a property with a "getKey" function or it
            // might be absent altogether
            Union <string, int> keyIfAny = null;
            Action <object>     refIfAny = null;

            if (propsIfAny != null)
            {
                // Pre-16, Bridge used to default to camel-casing property names and so a "Key" property would be named "key" and it would have a getter method
                // specified for it (it was possible to override these behaviours using PreserveMemberCase and [Name], [Template] or [FieldProperty] attributes)
                // but 16 has changed things such that the name casing is not changed (by default - this may also be altered using the "conventions" options)
                // and so we can't presume that a "Key" property will result in a JavaScript "key" property (or a "getKey" method).
                Script.Write(@"
					if (propsIfAny.key || (propsIfAny.key === 0)) { // Ensure that a zero key is not considered ""no-key-defined""
						keyIfAny = propsIfAny.key;
					}
					else if (propsIfAny.Key || (propsIfAny.Key === 0)) { // Ensure that a zero key is not considered ""no-key-defined""
						keyIfAny = propsIfAny.Key;
					}
					else if (propsIfAny.getKey && (typeof(propsIfAny.getKey) == ""function"")) {
						var keyIfAnyFromPropertyGetter = propsIfAny.getKey();
						if (keyIfAnyFromPropertyGetter || (keyIfAnyFromPropertyGetter === 0)) { // Ensure that a zero key is not considered ""no-key-defined""
							keyIfAny = keyIfAnyFromPropertyGetter;
						}
						else {
							keyIfAny = undefined;
						}
					}
					else {
						keyIfAny = undefined;
					}

					if (typeof(propsIfAny.ref) === ""function"") {
						refIfAny = propsIfAny.ref;
					}
					else if (typeof(propsIfAny.Ref) === ""function"") {
						refIfAny = propsIfAny.Ref;
					}
					else if (typeof(propsIfAny.getRef) === ""function"") {
						var refIfAnyFromPropertyGetter = propsIfAny.getRef();
						if (typeof(refIfAnyFromPropertyGetter) === ""function"") {
							refIfAny = refIfAnyFromPropertyGetter;
						}
						else {
							refIfAny = undefined;
						}
					}
					else {
						refIfAny = undefined;
					}
				"                );
            }

            // With the changes in React 15.0.0 (vs 0.14.7), a null Key value will be interpreted AS a key (and will either be ".$null" or ".$undefined")
            // when really we want a null Key to mean NO KEY. Possibly related to https://github.com/facebook/react/issues/2386, but I would have expected
            // to have seen this issue in 0.14 if it was that. The workaround is to return a type of "wrapped props" that doesn't even have a Key property
            // on it if there is no key value to use.
            var wrappedProps = new WrappedValue <TProps> {
                Value = propsIfAny
            };

            if (Script.Write <bool>("(typeof({0}) !== 'undefined')", keyIfAny))
            {
                Script.Write("{0}.key = {1}", wrappedProps, keyIfAny);
            }
            if (Script.Write <bool>("(typeof({0}) !== 'undefined')", refIfAny))
            {
                Script.Write("{0}.ref = {1}", wrappedProps, refIfAny);
            }
            return(wrappedProps);
        }