Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/rax-server-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rax-server-renderer",
"version": "0.6.5",
"version": "1.0.0",
"description": "Rax renderer for server-side render.",
"license": "BSD-3-Clause",
"main": "lib/index.js",
Expand All @@ -12,7 +12,7 @@
"url": "https://github.com/alibaba/rax/issues"
},
"homepage": "https://github.com/alibaba/rax#readme",
"devDependencies": {
"rax": "^0.6.5"
"peerDependencies": {
"rax": "^1.0.0"
}
}
16 changes: 16 additions & 0 deletions packages/rax-server-renderer/src/hookInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class HookInstance {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HookInstance 这个概念可以优化下,其实只有 instance的概念,没有 hook instance 的概念

constructor() {
this._hookID = 0;
this._hooks = {};
}

getHookID() {
return ++ this._hookID;
}

getHooks() {
return this._hooks;
}
}

export default HookInstance;
11 changes: 9 additions & 2 deletions packages/rax-server-renderer/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { shared } from 'rax';
import HookInstance from './hookInstance';

const EMPTY_OBJECT = {};
const TRUE = true;
const UNITLESS_NUMBER_PROPS = {
Expand Down Expand Up @@ -146,7 +149,6 @@ function renderElementToString(element, context, options) {

if (type) {
const props = element.props || EMPTY_OBJECT;

if (type.prototype && type.prototype.render) {
const instance = new type(props, context, updater); // eslint-disable-line new-cap
let currentContext = instance.context = context;
Expand Down Expand Up @@ -182,7 +184,12 @@ function renderElementToString(element, context, options) {
var renderedElement = instance.render();
return renderElementToString(renderedElement, currentContext, options);
} else if (typeof type === 'function') {
var renderedElement = type(props, context);
const instance = new HookInstance();
shared.Host.owner = {
_instance: instance
};

const renderedElement = type(props, context);
return renderElementToString(renderedElement, context, options);
} else if (typeof type === 'string') {
const isVoidElement = VOID_ELEMENTS[type];
Expand Down