Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 207012f

Browse files
committed
version 0.7.32 closes #88 closes #87 closes #86 closes #85 closes #83
1 parent 85efd52 commit 207012f

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

lib/react/component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def self.included(base)
1515
base.include(API)
1616
base.include(React::Callbacks)
1717
base.instance_eval do
18+
1819
class PropsWrapper
1920

2021
def initialize(props_hash)
@@ -39,8 +40,7 @@ def [](prop)
3940
define_callback :before_unmount
4041

4142
def deprecated_params_method(name, *args, &block)
42-
puts "deprecated_params_method for #{self.class.name}.#{name}"
43-
# TODO display deprecation message, but only once per access to a method
43+
self.class.deprecation_warning "Direct access to param `#{name}`. Use `params.#{name}` instead."
4444
params.send(name, *args, &block)
4545
end
4646

lib/react/component/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'react/component'
2+
13
module React
24
module Component
35
class Base

lib/react/component/class_methods.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ def process_exception(e, component, reraise = nil)
1818
raise e if reraise
1919
end
2020

21+
def deprecation_warning(message)
22+
@deprecation_messages ||= []
23+
message = "Warning: Deprecated feature used in #{self.name}. #{message}"
24+
unless @deprecation_messages.include? message
25+
@deprecation_messages << message
26+
IsomorphicHelpers.log message, :warning
27+
end
28+
end
29+
2130
def validator
2231
@validator ||= React::Validator.new(self)
2332
end
@@ -105,12 +114,14 @@ def param(*args)
105114
end
106115

107116
def required_param(name, options = {})
117+
deprecation_warning "`required_param` is deprecated, use `param` instead."
108118
validator.requires(name, options)
109119
end
110120

111121
alias_method :require_param, :required_param
112122

113123
def optional_param(name, options = {})
124+
deprecation_warning "`optional_param` is deprecated, use `param param_name: default_value` instead."
114125
validator.optional(name, options)
115126
end
116127

@@ -144,13 +155,16 @@ def export_state(*states, &block)
144155

145156
def define_state_methods(this, name, from = nil, &block)
146157
this.define_method("#{name}") do
158+
self.class.deprecation_warning "Direct access to state `#{name}`. Use `state.#{name}` instead." if from.nil? || from == this
147159
React::State.get_state(from || self, name)
148160
end
149161
this.define_method("#{name}=") do |new_state|
162+
self.class.deprecation_warning "Direct assignment to state `#{name}`. Use `#{(from && from != this) ? from : 'state'}.#{name}!` instead."
150163
yield name, React::State.get_state(from || self, name), new_state if block && block.arity > 0
151164
React::State.set_state(from || self, name, new_state)
152165
end
153166
this.define_method("#{name}!") do |*args|
167+
self.class.deprecation_warning "Direct access to state `#{name}`. Use `state.#{name}` instead." if from.nil? or from == this
154168
if args.count > 0
155169
yield name, React::State.get_state(from || self, name), args[0] if block && block.arity > 0
156170
current_value = React::State.get_state(from || self, name)

lib/react/top_level.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "native"
22
require 'active_support'
3-
require 'react/component'
3+
require 'react/component/base'
44

55
module React
66
HTML_TAGS = %w(a abbr address area article aside audio b base bdi bdo big blockquote body br
@@ -49,4 +49,13 @@ def self.render_to_static_markup(element)
4949
def self.unmount_component_at_node(node)
5050
`React.unmountComponentAtNode(node.$$class ? node[0] : node)`
5151
end
52+
5253
end
54+
55+
Element.instance_eval do
56+
class ::Element::DummyContext < React::Component::Base
57+
end
58+
def render(&block)
59+
React.render(React::RenderingContext.render(nil) {::Element::DummyContext.new.instance_eval &block}, self)
60+
end
61+
end if Object.const_defined?("Element")

lib/reactive-ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module React
2-
VERSION = "0.7.31"
2+
VERSION = "0.7.32"
33
end

0 commit comments

Comments
 (0)