isomorfeus-preact 10.5.2 → 10.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3ea3fdae9a37fa0da0126931e8049d583cbc00651c90446cb6cb42293758ab3
4
- data.tar.gz: a53ee376859447abdbce17955328181c0a0ac5ae01955917bd6f666e78c6ee7d
3
+ metadata.gz: d7b98a0ea532f106d129705403fe6380883cb163c5d3aa947bf90e452e2b8982
4
+ data.tar.gz: c08be6c7a4d0eaf6061ad4e61e90f4013c0b888137732e6041a4e1c48970aca0
5
5
  SHA512:
6
- metadata.gz: 1dde38864d857da7e028cefeb336c420b6901289ff5d183f2cdc70aca6fc10520e41a3b0a00d8509b155921b2343f1d9bb42259cf0ca99b8da2f0c1354b67c4f
7
- data.tar.gz: 5800f128d17159d0b86193095d5b3064a8992ef8db70d72a5eee67c1ffdcde1cd19939eaffe52168f9a8fae0ebed393badc7b5d6ca066b345de6650ec3b371ca
6
+ metadata.gz: b1bb607e54cb39d7619f61be717971731e459dc3db0593ae18655586cae52300bb6d56752175127921fd142d9c430e719c043d2b1acc279b4b4829c65bc23134
7
+ data.tar.gz: 8bf655b3180949f71dbbedcce76b90470abbec11f6045fe5f1a649036438fe72b88a40907e90d94efadbe659c26c207fab2143a8cb960a987769b73aad19e427
@@ -87,22 +87,11 @@ module Isomorfeus
87
87
  end
88
88
 
89
89
  def force_render
90
- begin
91
- if Isomorfeus.top_component
92
- Preact.find_dom_node(Isomorfeus.top_component) if on_browser? || on_desktop? # if not mounted will raise
93
- if `typeof Opal.global.deepForceUpdate === 'undefined'`
94
- Isomorfeus.top_component.JS.forceUpdate()
95
- else
96
- `Opal.global.deepForceUpdate(#{Isomorfeus.top_component})`
97
- end
98
- end
99
- rescue Exception => e
100
- # TODO try mount first
101
- # if it fails
102
- `console.error("force_render failed'! Error: " + #{e.message} + "! Reloading page.")`
103
- `location.reload()` if on_browser?
104
- end
90
+ `Opal.Preact.deep_force_update(#{Isomorfeus.top_component})`
105
91
  nil
92
+ rescue Exception => e
93
+ `console.error("force_render failed'! Error: " + #{e.message} + "! Reloading page.")`
94
+ `location.reload()` if on_browser?
106
95
  end
107
96
  end
108
97
 
@@ -142,14 +131,12 @@ module Isomorfeus
142
131
 
143
132
  class << self
144
133
  def raise_error(error: nil, error_class: nil, message: nil, stack: nil)
145
- error_class = error.class unless error == nil
134
+ error_class = error.class if error
146
135
 
147
136
  error_class = RuntimeError unless error_class
148
137
  execution_environment = if on_browser? then 'on Browser'
149
138
  elsif on_ssr? then 'in Server Side Rendering'
150
139
  elsif on_server? then 'on Server'
151
- elsif on_mobile? then 'on Mobile'
152
- elsif on_database? then 'on Database'
153
140
  else
154
141
  'on Client'
155
142
  end
@@ -2,11 +2,11 @@ module Isomorfeus
2
2
  module Preact
3
3
  module Imports
4
4
  def self.add
5
- Isomorfeus.add_common_js_import('preact', 'Preact')
6
- Isomorfeus.add_common_js_import('preact/hooks', 'PreactHooks')
5
+ Isomorfeus.add_common_js_import('preact', 'Preact', '*')
6
+ Isomorfeus.add_common_js_import('preact/hooks', 'PreactHooks', '*')
7
7
  Isomorfeus.add_common_js_import('wouter-preact', nil, ['Router', 'Link', 'Redirect', 'Route', 'Switch'])
8
8
 
9
- Isomorfeus.add_common_js_import('nano-css', 'NanoCSS')
9
+ Isomorfeus.add_common_js_import('nano-css', 'NanoCSS', '*')
10
10
  %w[rule sheet nesting hydrate unitless global keyframes].each do |addon|
11
11
  Isomorfeus.add_common_js_import("nano-css/addon/#{addon}", 'NanoCSSAddons', 'addon', addon)
12
12
  end
@@ -17,9 +17,6 @@ module Isomorfeus
17
17
  Isomorfeus.add_ssr_js_import('wouter-preact/static-location', 'staticLocationHook')
18
18
 
19
19
  Isomorfeus.add_web_js_import('wouter-preact/use-location', 'locationHook')
20
- if Isomorfeus.development?
21
- Isomorfeus.add_web_js_import('preact-deep-force-update', 'deepForceUpdate')
22
- end
23
20
 
24
21
  if Dir.exist?(Isomorfeus.app_root)
25
22
  Isomorfeus.add_common_ruby_import('isomorfeus_loader') if File.exist?(File.join(Isomorfeus.app_root, 'isomorfeus_loader.rb'))
@@ -16,12 +16,12 @@ module Isomorfeus
16
16
  render_result
17
17
  end
18
18
 
19
- def mount_component(component_name, props = {}, asset_key = 'ssr.js')
19
+ def mount_component(component_name, props = {}, asset_key = 'ssr.js', skip_ssr: false, use_ssr: false)
20
20
  @ssr_response_status = nil
21
21
  @ssr_styles = nil
22
22
  thread_id_asset = "#{Thread.current.object_id}#{asset_key}"
23
23
  render_result = "<div data-iso-env=\"#{Isomorfeus.env}\" data-iso-root=\"#{component_name}\" data-iso-props='#{Oj.dump(props, mode: :strict)}'"
24
- if Isomorfeus.server_side_rendering
24
+ if !skip_ssr && (Isomorfeus.server_side_rendering || use_ssr)
25
25
  if Isomorfeus.development?
26
26
  # always create a new context, effectively reloading code
27
27
  # delete the existing context first, saves memory
@@ -31,22 +31,23 @@ module Isomorfeus
31
31
  runtime.vm.delete_context(uuid)
32
32
  end
33
33
  begin
34
- asset = Isomorfeus.assets[asset_key]
35
- raise "#{self.class.name}: Asset not found: #{asset_key}" unless asset
36
- asset_manager.transition(asset_key, asset)
37
- Isomorfeus.ssr_contexts[thread_id_asset] = ExecJS.permissive_compile(asset.bundle)
34
+ init_speednode_context(asset_key, thread_id_asset)
38
35
  rescue Exception => e
39
36
  Isomorfeus.raise_error(message: "Server Side Rendering: Failed creating context for #{asset_key}. Error: #{e.message}", stack: e.backtrace)
40
37
  end
41
38
  else
42
- # initialize speednode context
43
39
  unless Isomorfeus.ssr_contexts.key?(thread_id_asset)
44
- asset = Isomorfeus.assets[asset_key]
45
- raise "#{self.class.name}: Asset not found: #{asset_key}" unless asset
46
- asset_manager.transition(asset_key, asset)
47
- Isomorfeus.ssr_contexts[thread_id_asset] = ExecJS.permissive_compile(asset.bundle)
40
+ init_speednode_context(asset_key, thread_id_asset)
48
41
  end
49
42
  end
43
+
44
+ # if location_host and scheme are given and if Transport is loaded, connect and then render,
45
+ # otherwise do not render because only one pass is required
46
+ ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
47
+ location_host = props[:location_host] ? props[:location_host] : 'localhost'
48
+ api_ws_path = Isomorfeus.respond_to?(:api_websocket_path) ? Isomorfeus.api_websocket_path : ''
49
+ transport_ws_url = ws_scheme + location_host + api_ws_path
50
+
50
51
  # build javascript for rendering first pass
51
52
  # it will initialize buffers to guard against leaks, maybe caused by previous exceptions
52
53
  javascript = <<~JAVASCRIPT
@@ -63,14 +64,6 @@ module Isomorfeus
63
64
  global.Opal.Isomorfeus['$force_init!']();
64
65
  global.Opal.Isomorfeus['$ssr_response_status='](200);
65
66
  global.Opal.Isomorfeus.TopLevel['$ssr_route_path=']('#{props[:location]}');
66
- JAVASCRIPT
67
- # if location_host and scheme are given and if Transport is loaded, connect and then render,
68
- # otherwise do not render because only one pass is required
69
- ws_scheme = props[:location_scheme] == 'https:' ? 'wss:' : 'ws:'
70
- location_host = props[:location_host] ? props[:location_host] : 'localhost'
71
- api_ws_path = Isomorfeus.respond_to?(:api_websocket_path) ? Isomorfeus.api_websocket_path : ''
72
- transport_ws_url = ws_scheme + location_host + api_ws_path
73
- javascript << <<~JAVASCRIPT
74
67
  let api_ws_path = '#{api_ws_path}';
75
68
  let exception;
76
69
  if (typeof global.Opal.Isomorfeus.Transport !== 'undefined' && api_ws_path !== '') {
@@ -176,5 +169,12 @@ module Isomorfeus
176
169
  def component_cache
177
170
  @_component_cache ||= Isomorfeus.component_cache_init_block.call
178
171
  end
172
+
173
+ def init_speednode_context(asset_key, thread_id_asset)
174
+ asset = Isomorfeus.assets[asset_key]
175
+ raise "#{self.class.name}: Asset not found: #{asset_key}" unless asset
176
+ asset_manager.transition(asset_key, asset)
177
+ Isomorfeus.ssr_contexts[thread_id_asset] = ExecJS.permissive_compile(asset.bundle)
178
+ end
179
179
  end
180
180
  end
@@ -65,7 +65,7 @@ module Isomorfeus
65
65
  def type!
66
66
  return if @o[:allow_nil] && @v.nil?
67
67
  if @o.key?(:class)
68
- Isomorfeus.raise_error(message: "#{@c}: #{@p} class not #{@o[:class]}") unless @v.class == @o[:class]
68
+ Isomorfeus.raise_error(message: "#{@c}: #{@p} class is not #{@o[:class]}") unless @v.class == @o[:class]
69
69
  elsif @o.key?(:is_a)
70
70
  Isomorfeus.raise_error(message: "#{@c}: #{@p} is not a #{@o[:is_a]}") unless @v.is_a?(@o[:is_a])
71
71
  elsif @o.key?(:type)
@@ -89,12 +89,9 @@ module Isomorfeus
89
89
  element = element_or_query
90
90
  end
91
91
 
92
- top = if hydrated
93
- Preact.hydrate(Preact.create_element(component, props), element)
94
- else
95
- Preact.render(Preact.create_element(component, props), element)
96
- end
97
- Isomorfeus.top_component = top if top
92
+ top = Preact.create_element(component, props)
93
+ hydrated ? Preact.hydrate(top, element) : Preact.render(top, element)
94
+ Isomorfeus.top_component = top
98
95
  end
99
96
  end
100
97
  end
@@ -1,3 +1,3 @@
1
1
  module Preact
2
- VERSION = '10.5.2'
2
+ VERSION = '10.5.6'
3
3
  end
data/lib/preact.rb CHANGED
@@ -213,6 +213,21 @@ module Preact
213
213
  operabu[operabu.length - 1].push(Opal.global.Preact.createElement(component, native_props));
214
214
  }
215
215
  };
216
+
217
+ self.deep_force_update = function(component) {
218
+ if (component.forceUpdate) { component.forceUpdate(); }
219
+ if (component.__c) { self.deep_force_update(component.__c); }
220
+ else if (component.base) { self.update_components_from_dom(component.base); }
221
+ };
222
+
223
+ self.update_components_from_dom = function(node, fn) {
224
+ let children = node.childNodes;
225
+ for (let i=children && children.length; i--;) {
226
+ let child = children[i];
227
+ if (child.__c) { self.deep_force_update(child.__c); }
228
+ else { self.update_components_from_dom(child, fn); }
229
+ }
230
+ };
216
231
  }
217
232
 
218
233
 
@@ -264,13 +279,8 @@ module Preact
264
279
  Preact::Ref.new(`Opal.global.Preact.createRef()`)
265
280
  end
266
281
 
267
- def self.hydrate(native_preact_element, container_node, replace_node, &block)
268
- # container is a native DOM element
269
- if block_given?
270
- `Opal.global.Preact.hydrate(native_preact_element, container_node, function() { block.$call() })`
271
- else
272
- `Opal.global.Preact.hydrate(native_preact_element, container_node)`
273
- end
282
+ def self.hydrate(native_preact_element, container_node, replace_node)
283
+ `Opal.global.Preact.hydrate(native_preact_element, container_node)`
274
284
  end
275
285
 
276
286
  def self.location_hook(location)
@@ -134,14 +134,6 @@
134
134
  "url": "https://opencollective.com/preact"
135
135
  }
136
136
  },
137
- "node_modules/preact-deep-force-update": {
138
- "version": "0.1.0",
139
- "resolved": "https://registry.npmjs.org/preact-deep-force-update/-/preact-deep-force-update-0.1.0.tgz",
140
- "integrity": "sha1-IWazTsISfLZ1UsouD73Sdsh4bPw=",
141
- "peerDependencies": {
142
- "preact": "*"
143
- }
144
- },
145
137
  "node_modules/preact-render-to-string": {
146
138
  "version": "5.1.19",
147
139
  "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.1.19.tgz",
data/package.json CHANGED
@@ -3,7 +3,6 @@
3
3
  "dependencies": {
4
4
  "nano-css": "^5.3.4",
5
5
  "preact": "^10.5.14",
6
- "preact-deep-force-update": "^0.1.0",
7
6
  "preact-render-to-string": "^5.1.19",
8
7
  "wouter-preact": "^2.7.4"
9
8
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-preact
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.5.2
4
+ version: 10.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-03 00:00:00.000000000 Z
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: oj
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.13.3
33
+ version: 3.13.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.13.3
40
+ version: 3.13.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: opal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,44 +84,44 @@ dependencies:
84
84
  name: isomorfeus-asset-manager
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.12.0
89
+ version: 0.12.4
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.12.0
96
+ version: 0.12.4
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isomorfeus-redux
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 4.1.4
103
+ version: 4.1.6
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 4.1.4
110
+ version: 4.1.6
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: isomorfeus-speednode
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.4.0
117
+ version: 0.4.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.4.0
124
+ version: 0.4.1
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: dalli
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -168,16 +168,16 @@ dependencies:
168
168
  name: isomorfeus-puppetmaster
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.5.0
173
+ version: 0.5.2
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 0.5.0
180
+ version: 0.5.2
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -921,21 +921,6 @@ files:
921
921
  - node_modules/object-assign/license
922
922
  - node_modules/object-assign/package.json
923
923
  - node_modules/object-assign/readme.md
924
- - node_modules/preact-deep-force-update/.babelrc
925
- - node_modules/preact-deep-force-update/.eslintrc
926
- - node_modules/preact-deep-force-update/.npmignore
927
- - node_modules/preact-deep-force-update/.travis.yml
928
- - node_modules/preact-deep-force-update/LICENSE
929
- - node_modules/preact-deep-force-update/README.md
930
- - node_modules/preact-deep-force-update/dist/deep-force-update.js
931
- - node_modules/preact-deep-force-update/dist/deep-force-update.js.map
932
- - node_modules/preact-deep-force-update/dist/deep-force-update.min.js
933
- - node_modules/preact-deep-force-update/dist/deep-force-update.min.js.map
934
- - node_modules/preact-deep-force-update/karma.conf.js
935
- - node_modules/preact-deep-force-update/package.json
936
- - node_modules/preact-deep-force-update/rollup.config.js
937
- - node_modules/preact-deep-force-update/src/index.js
938
- - node_modules/preact-deep-force-update/test/index.js
939
924
  - node_modules/preact-render-to-string/LICENSE
940
925
  - node_modules/preact-render-to-string/README.md
941
926
  - node_modules/preact-render-to-string/dist/commonjs.js
@@ -1,8 +0,0 @@
1
- {
2
- "presets": ["es2015-minimal", "stage-0", "react"],
3
- "plugins": [
4
- "transform-class-properties",
5
- ["transform-es2015-classes", { "loose":true }],
6
- ["transform-react-jsx", { "pragma":"h" }]
7
- ]
8
- }
@@ -1,66 +0,0 @@
1
- {
2
- "parser": "babel-eslint",
3
- "extends": "eslint:recommended",
4
- "plugins": [
5
- "react"
6
- ],
7
- "env": {
8
- "browser": true,
9
- "mocha": true,
10
- "es6": true,
11
- "node": true
12
- },
13
- "parserOptions": {
14
- "ecmaFeatures": {
15
- "modules": true,
16
- "jsx": true
17
- }
18
- },
19
- "globals": {
20
- "sinon": true,
21
- "expect": true
22
- },
23
- "rules": {
24
- "react/jsx-uses-react": 2,
25
- "react/jsx-uses-vars": 2,
26
- "no-unused-vars": [1, { "varsIgnorePattern": "^h$" }],
27
- "no-cond-assign": 1,
28
- "no-empty": 0,
29
- "no-console": 1,
30
- "semi": 2,
31
- "camelcase": 0,
32
- "comma-style": 2,
33
- "comma-dangle": [2, "never"],
34
- "indent": [2, "tab", {"SwitchCase": 1}],
35
- "no-mixed-spaces-and-tabs": [2, "smart-tabs"],
36
- "no-trailing-spaces": [2, { "skipBlankLines": true }],
37
- "max-nested-callbacks": [2, 5],
38
- "no-eval": 2,
39
- "no-implied-eval": 2,
40
- "no-new-func": 2,
41
- "guard-for-in": 2,
42
- "eqeqeq": 0,
43
- "no-else-return": 2,
44
- "no-redeclare": 2,
45
- "no-dupe-keys": 2,
46
- "radix": 2,
47
- "strict": [2, "never"],
48
- "no-shadow": 0,
49
- "callback-return": [1, ["callback", "cb", "next", "done"]],
50
- "no-delete-var": 2,
51
- "no-undef-init": 2,
52
- "no-shadow-restricted-names": 2,
53
- "handle-callback-err": 0,
54
- "no-lonely-if": 2,
55
- "keyword-spacing": 2,
56
- "constructor-super": 2,
57
- "no-this-before-super": 2,
58
- "no-dupe-class-members": 2,
59
- "no-const-assign": 2,
60
- "prefer-spread": 2,
61
- "no-useless-concat": 2,
62
- "no-var": 2,
63
- "object-shorthand": 2,
64
- "prefer-arrow-callback": 2
65
- }
66
- }
@@ -1,2 +0,0 @@
1
- !/dist
2
- !/src
@@ -1,3 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 4
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Jason Miller
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,53 +0,0 @@
1
- # preact-deep-force-update
2
-
3
- [![NPM](http://img.shields.io/npm/v/preact-deep-force-update.svg)](https://www.npmjs.com/package/preact-deep-force-update)
4
- [![travis-ci](https://travis-ci.org/developit/preact-deep-force-update.svg)](https://travis-ci.org/developit/preact-deep-force-update)
5
-
6
- Recursively invoke forceUpdate() on a tree of components.
7
-
8
- #### [JSFiddle Example](https://jsfiddle.net/developit/642ctu04/)
9
-
10
-
11
- ---
12
-
13
-
14
- ### Usage Example
15
-
16
- ```js
17
- import { h, Component, render } from 'preact';
18
- import deepForceUpdate from 'preact-deep-force-update';
19
-
20
- class Main extends Component {
21
- render() {
22
- return <div><Inner /></div>;
23
- }
24
- }
25
-
26
- class Inner extends Component {
27
- render() {
28
- let time = new Date().toTimeString();
29
- return <span>{time}</span>;
30
- }
31
- }
32
-
33
- let main;
34
- render(<Main ref={c => main=c } />, document.body);
35
-
36
- // force an update to the whole tree:
37
- deepForceUpdate(main);
38
-
39
- // you can also pass an Element:
40
- deepForceUpdate(document.body.firstChild);
41
- ```
42
-
43
-
44
- ---
45
-
46
-
47
- ### License
48
-
49
- [MIT]
50
-
51
-
52
- [Preact]: https://github.com/developit/preact
53
- [MIT]: http://choosealicense.com/licenses/mit/
@@ -1,36 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global.preactDeepForceUpdate = factory());
5
- }(this, function () {
6
-
7
- /** Invoke `.forceUpdate()` on a component and all descendants. */
8
- function deepForceUpdate(component) {
9
- if (component.forceUpdate) {
10
- component.forceUpdate();
11
- }
12
-
13
- // high-order child recursion
14
- if (component._component) {
15
- deepForceUpdate(component._component);
16
- } else if (component.base) {
17
- updateComponentsFromDom(component.base);
18
- }
19
- }
20
-
21
- function updateComponentsFromDom(node, fn) {
22
- var children = node.childNodes;
23
- for (var i = children && children.length; i--;) {
24
- var child = children[i];
25
- if (child._component) {
26
- deepForceUpdate(child._component);
27
- } else {
28
- updateComponentsFromDom(child, fn);
29
- }
30
- }
31
- }
32
-
33
- return deepForceUpdate;
34
-
35
- }));
36
- //# sourceMappingURL=deep-force-update.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":null,"sources":["../src/index.js"],"sourcesContent":["/** Invoke `.forceUpdate()` on a component and all descendants. */\nexport default function deepForceUpdate(component) {\n\tif (component.forceUpdate) {\n\t\tcomponent.forceUpdate();\n\t}\n\n\t// high-order child recursion\n\tif (component._component) {\n\t\tdeepForceUpdate(component._component);\n\t}\n\telse if (component.base) {\n\t\tupdateComponentsFromDom(component.base);\n\t}\n}\n\nfunction updateComponentsFromDom(node, fn) {\n\tlet children = node.childNodes;\n\tfor (let i=children && children.length; i--; ) {\n\t\tlet child = children[i];\n\t\tif (child._component) {\n\t\t\tdeepForceUpdate(child._component);\n\t\t}\n\t\telse {\n\t\t\tupdateComponentsFromDom(child, fn);\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;CAAA;AACA,AAAe,CAAA,SAAS,eAAT,CAAyB,SAAzB,EAAoC;AAClD,CAAA,KAAI,UAAU,WAAd,EAA2B;AAC1B,CAAA,YAAU,WAAV;AACA,CAAA;;AAED,CAAA;AACA,CAAA,KAAI,UAAU,UAAd,EAA0B;AACzB,CAAA,kBAAgB,UAAU,UAA1B;AACA,CAAA,EAFD,MAGK,IAAI,UAAU,IAAd,EAAoB;AACxB,CAAA,0BAAwB,UAAU,IAAlC;AACA,CAAA;AACD,CAAA;;AAED,CAAA,SAAS,uBAAT,CAAiC,IAAjC,EAAuC,EAAvC,EAA2C;AAC1C,CAAA,KAAI,WAAW,KAAK,UAApB;AACA,CAAA,MAAK,IAAI,IAAE,YAAY,SAAS,MAAhC,EAAwC,GAAxC,GAA+C;AAC9C,CAAA,MAAI,QAAQ,SAAS,CAAT,CAAZ;AACA,CAAA,MAAI,MAAM,UAAV,EAAsB;AACrB,CAAA,mBAAgB,MAAM,UAAtB;AACA,CAAA,GAFD,MAGK;AACJ,CAAA,2BAAwB,KAAxB,EAA+B,EAA/B;AACA,CAAA;AACD,CAAA;AACD,CAAA;;;;"}
@@ -1,2 +0,0 @@
1
- !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):e.preactDeepForceUpdate=o()}(this,function(){function e(n){n.forceUpdate&&n.forceUpdate(),n._component?e(n._component):n.base&&o(n.base)}function o(n,t){for(var c=n.childNodes,f=c&&c.length;f--;){var p=c[f];p._component?e(p._component):o(p,t)}}return e});
2
- //# sourceMappingURL=deep-force-update.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["deepForceUpdate","component","forceUpdate","_component","base","updateComponentsFromDom","node","fn","children","childNodes","i","length","child"],"mappings":"oLACe,QAASA,GAAgBC,GACnCA,EAAUC,aACbD,EAAUC,cAIPD,EAAUE,WACbH,EAAgBC,EAAUE,YAElBF,EAAUG,MAClBC,EAAwBJ,EAAUG,MAIpC,QAASC,GAAwBC,EAAMC,GAEtC,IAAK,GADDC,GAAWF,EAAKG,WACXC,EAAEF,GAAYA,EAASG,OAAQD,KAAO,CAC9C,GAAIE,GAAQJ,EAASE,EACjBE,GAAMT,WACTH,EAAgBY,EAAMT,YAGtBE,EAAwBO,EAAOL","file":"deep-force-update.min.js"}
@@ -1,32 +0,0 @@
1
- module.exports = function(config) {
2
- config.set({
3
- frameworks: ['mocha', 'chai-sinon'],
4
- reporters: ['mocha'],
5
- browsers: ['PhantomJS'],
6
-
7
- files: ['test/**/*.js'],
8
-
9
- preprocessors: {
10
- '{src,test}/**/*.js': ['webpack', 'sourcemap']
11
- },
12
-
13
- webpack: {
14
- module: {
15
- loaders: [{
16
- test: /\.jsx?$/,
17
- exclude: /node_modules/,
18
- loader: 'babel'
19
- }]
20
- },
21
- resolve: {
22
- alias: {
23
- src: __dirname+'/src'
24
- }
25
- }
26
- },
27
-
28
- webpackMiddleware: {
29
- noInfo: true
30
- }
31
- });
32
- };
@@ -1,80 +0,0 @@
1
- {
2
- "name": "preact-deep-force-update",
3
- "amdName": "preactDeepForceUpdate",
4
- "version": "0.1.0",
5
- "description": "Recursively invoke forceUpdate() on a tree of components.",
6
- "main": "dist/deep-force-update.js",
7
- "jsnext:main": "src/index.js",
8
- "minified:main": "dist/deep-force-update.min.js",
9
- "scripts": {
10
- "clean": "rimraf dist/",
11
- "build": "npm-run-all clean transpile minify size",
12
- "transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main",
13
- "minify": "uglifyjs $npm_package_main -cm -o $npm_package_minified_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_minified_main}.map",
14
- "size": "size=$(gzip-size $npm_package_minified_main) && echo \"gzip size: $size / $(pretty-bytes $size)\"",
15
- "test": "npm-run-all lint build test:karma",
16
- "lint": "eslint {src,test}",
17
- "test:karma": "karma start --single-run",
18
- "test:watch": "karma start",
19
- "prepublish": "npm-run-all build test",
20
- "release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
21
- },
22
- "keywords": [
23
- "preact",
24
- "update",
25
- "force"
26
- ],
27
- "author": "Jason Miller <jason@developit.ca>",
28
- "license": "MIT",
29
- "repository": {
30
- "type": "git",
31
- "url": "https://github.com/developit/preact-deep-force-update.git"
32
- },
33
- "bugs": {
34
- "url": "https://github.com/developit/preact-deep-force-update/issues"
35
- },
36
- "homepage": "https://github.com/developit/preact-deep-force-update",
37
- "peerDependencies": {
38
- "preact": "*"
39
- },
40
- "devDependencies": {
41
- "babel-cli": "^6.9.0",
42
- "babel-core": "^6.9.1",
43
- "babel-eslint": "^6.0.4",
44
- "babel-loader": "^6.2.4",
45
- "babel-plugin-transform-class-properties": "^6.9.1",
46
- "babel-plugin-transform-es2015-classes": "^6.9.0",
47
- "babel-plugin-transform-react-jsx": "^6.8.0",
48
- "babel-preset-es2015": "^6.9.0",
49
- "babel-preset-es2015-minimal": "^2.0.0",
50
- "babel-preset-es2015-minimal-rollup": "^2.0.0",
51
- "babel-preset-react": "^6.5.0",
52
- "babel-preset-stage-0": "^6.5.0",
53
- "chai": "^3.5.0",
54
- "diff": "^2.2.3",
55
- "eslint": "^3.0.0",
56
- "eslint-plugin-react": "^5.1.1",
57
- "gzip-size-cli": "^1.0.0",
58
- "karma": "^1.0.0",
59
- "karma-chai-sinon": "^0.1.5",
60
- "karma-mocha": "^1.0.1",
61
- "karma-mocha-reporter": "^2.0.3",
62
- "karma-phantomjs-launcher": "^1.0.0",
63
- "karma-sourcemap-loader": "^0.3.7",
64
- "karma-webpack": "^1.7.0",
65
- "mkdirp": "^0.5.1",
66
- "mocha": "^2.5.0",
67
- "npm-run-all": "^2.0.0",
68
- "phantomjs-prebuilt": "^2.1.7",
69
- "preact": "^5.3.1",
70
- "pretty-bytes-cli": "^1.0.0",
71
- "rimraf": "^2.5.1",
72
- "rollup": "^0.34.1",
73
- "rollup-plugin-babel": "^2.4.0",
74
- "rollup-plugin-memory": "^1.0.0",
75
- "sinon": "^1.17.4",
76
- "sinon-chai": "^2.8.0",
77
- "uglify-js": "^2.6.1",
78
- "webpack": "^1.13.1"
79
- }
80
- }
@@ -1,17 +0,0 @@
1
- import fs from 'fs';
2
- import babel from 'rollup-plugin-babel';
3
-
4
- var babelRc = JSON.parse(fs.readFileSync('.babelrc','utf8')); // eslint-disable-line
5
-
6
- export default {
7
- exports: 'default',
8
- useStrict: false,
9
- plugins: [
10
- babel({
11
- babelrc: false,
12
- presets: ['es2015-minimal-rollup'].concat(babelRc.presets.slice(1)),
13
- plugins: babelRc.plugins,
14
- exclude: 'node_modules/**'
15
- })
16
- ]
17
- };
@@ -1,27 +0,0 @@
1
- /** Invoke `.forceUpdate()` on a component and all descendants. */
2
- export default function deepForceUpdate(component) {
3
- if (component.forceUpdate) {
4
- component.forceUpdate();
5
- }
6
-
7
- // high-order child recursion
8
- if (component._component) {
9
- deepForceUpdate(component._component);
10
- }
11
- else if (component.base) {
12
- updateComponentsFromDom(component.base);
13
- }
14
- }
15
-
16
- function updateComponentsFromDom(node, fn) {
17
- let children = node.childNodes;
18
- for (let i=children && children.length; i--; ) {
19
- let child = children[i];
20
- if (child._component) {
21
- deepForceUpdate(child._component);
22
- }
23
- else {
24
- updateComponentsFromDom(child, fn);
25
- }
26
- }
27
- }
@@ -1,50 +0,0 @@
1
- import { h, Component, render } from 'preact';
2
- import deepForceUpdate from 'src';
3
-
4
- describe('deepForceUpdate', () => {
5
- let scratch = document.createElement('div');
6
-
7
- before( () => document.body.appendChild(scratch) );
8
- afterEach( () => scratch.innerHTML = '' );
9
- after( () => document.body.removeChild(scratch) );
10
-
11
- it('should force updates', () => {
12
- let renders = {
13
- outer: 0,
14
- inner: 0
15
- };
16
-
17
- class Outer extends Component {
18
- render() {
19
- renders.outer++;
20
- return <div><Inner /></div>;
21
- }
22
- }
23
-
24
- class Inner extends Component {
25
- render() {
26
- renders.inner++;
27
- let time = new Date().toTimeString();
28
- return <span>{time}</span>;
29
- }
30
- }
31
-
32
- let outer;
33
- let root = render(<Outer ref={c => outer=c } />, scratch);
34
-
35
- expect(renders).to.have.property('outer', 1);
36
- expect(renders).to.have.property('inner', 1);
37
-
38
- // force an update to the whole tree:
39
- deepForceUpdate(outer);
40
-
41
- expect(renders).to.have.property('outer', 2);
42
- expect(renders).to.have.property('inner', 3);
43
-
44
- // you can also pass an Element:
45
- deepForceUpdate(root);
46
-
47
- expect(renders).to.have.property('outer', 3);
48
- expect(renders).to.have.property('inner', 5);
49
- });
50
- });